Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apiv2 swagger and add minimal swagger test #2782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Fix apiv2 swagger with harvest metadata and add apiv2 swagger tests [#2782](https://github.com/opendatateam/udata/pull/2782)

## 5.0.1 (2022-11-14)

Expand Down
3 changes: 3 additions & 0 deletions udata/core/dataset/apiv2.py
Expand Up @@ -16,6 +16,7 @@
user_ref_fields,
checksum_fields,
dataset_harvest_fields,
resource_harvest_fields
)
from udata.core.spatial.api_fields import geojson
from .models import (
Expand Down Expand Up @@ -159,6 +160,8 @@
apiv2.inherit('TemporalCoverage', temporal_coverage_fields)
apiv2.inherit('GeoJSON', geojson)
apiv2.inherit('Checksum', checksum_fields)
apiv2.inherit('HarvestDatasetMetadata', dataset_harvest_fields)
apiv2.inherit('HarvestResourceMetadata', resource_harvest_fields)


@ns.route('/search/', endpoint='dataset_search')
Expand Down
26 changes: 26 additions & 0 deletions udata/tests/apiv2/test_swagger.py
@@ -0,0 +1,26 @@
import json

from flask import url_for
from flask_restx import schemas

from udata.tests.helpers import assert200


class SwaggerBlueprintTest:
modules = []

def test_swagger_resource_type(self, api):
response = api.get(url_for('apiv2.specs'))
assert200(response)
swagger = json.loads(response.data)
expected = swagger['paths']['/datasets/{dataset}/resources/']
expected = expected['get']['responses']['200']['schema']['$ref']
assert expected == '#/definitions/ResourcePage'

def test_swagger_specs_validate(self, api):
response = api.get(url_for('apiv2.specs'))
try:
schemas.validate(response.json)
except schemas.SchemaValidationError as e:
print(e.errors)
raise