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

OpenAPI validations fails due to incorrect type of "dimension_types" #478

Closed
2 tasks done
ml-evs opened this issue Aug 31, 2020 · 1 comment · Fixed by #480
Closed
2 tasks done

OpenAPI validations fails due to incorrect type of "dimension_types" #478

ml-evs opened this issue Aug 31, 2020 · 1 comment · Fixed by #480
Labels
bug Something isn't working schema Concerns the schema models

Comments

@ml-evs
Copy link
Member

ml-evs commented Aug 31, 2020

This is the cause of Materials-Consortia/OPTIMADE#314, which @CasperWA has summarised below.

The problem is that we are using (approximately) Tuple[PERIODICITY, PERIODICITY, PERIODICITY] when constructing dimension_types, but the pydantic docs (link below) states that:

Python type JSON Schema Type Additional JSON Schema Defined in
Tuple[str, int] array {"items": [{"type": "string"}, {"type": "integer"}]} JSON Schema Validation

And equivalently for any other set of subtypes. Note: If using schemas for OpenAPI, you shouldn't use this declaration, as it would not be valid in OpenAPI (although it is valid in JSON Schema).

Steps to take for the fix:

  • Run an openapi validator in our CI.
  • Switch away from Tuple throughout our API models (what should we use instead?)

From @CasperWA:

I notice that we still don't validate properly according to swagger (see recent issue on the spec repo)...
https://validator.swagger.io/validator/debug?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/a6926f53263fcabc91523e974c4d4b5bbe5bc9f1/openapi/openapi.json

Okay, I think I may have found the issue here.
According to the OpenAPI specification the items property of a Schema Object MUST be an object. But for dimension_types, it's an array.
Edit: The issue is also mentioned in pydantic's documentation here (see in the table for Tuple).

Originally posted by @CasperWA in #477 (comment)

@ml-evs ml-evs added bug Something isn't working schema Concerns the schema models labels Aug 31, 2020
@CasperWA
Copy link
Member

  • Run an openapi validator in our CI.

We already are (openapi-spec-validator).
But perhaps we should switch to requests to https://validator.swagger.io/validator/debug?url=https://raw.githubusercontent.com/Materials-Consortia/optimade-python-tools/tree/master/openapi/openapi.json ?

  • Switch away from Tuple throughout our API models (what should we use instead?)

I have done this by using conlist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working schema Concerns the schema models
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants