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

Swagger deserializer ignores JsonSchema.types() for v3.1.0 #1821

Closed
jokoroukwu opened this issue Oct 6, 2022 · 2 comments
Closed

Swagger deserializer ignores JsonSchema.types() for v3.1.0 #1821

jokoroukwu opened this issue Oct 6, 2022 · 2 comments

Comments

@jokoroukwu
Copy link

jokoroukwu commented Oct 6, 2022

Consider the following schema:

Rule:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        condition:
          type: string
        order:
          type: integer
        enabled:
          type: boolean
        actions:
          type: array
          description: List of actions launched on rule execution
          items:
            $ref: '#/components/schemas/ActionDescriptor'
        version:
          type: integer
          description: Version counter

This schema is deserialized into JsonSchema.
The type is present in JsonSchema.types but for some reason the actual JsonSchema.type is set to "object".
image

I've found that the object type is set in ResolveFully.resolveSchema()
if (property.getProperties() != model.getProperties()) { if (property.getType() == null) { property.setType("object"); }

Also if the open api is of version 3.1 which is in my case then OpenAPIDeserializer.getJsonSchema() is being invoked which eventually sets type via schema.addType(typeString);.
However If open api version is different then 'OpenAPIDeserializer.getSchema()' is being invoked and in this case the type is set via schema.setType(value);

@spacether
Copy link
Contributor

Related #1801

@frantuma
Copy link
Member

frantuma commented Nov 2, 2022

This has been addressed by #1846 (fixed bug for 3.1 setting type instead of types and swagger-api/swagger-core#4285.

When deserializing/parsing OAS 3.1 / JSON Schema 2020/12 documents, the type field is deserialized into Schema.types member (as draft 2020/12 supports array of types), while with OAS 3.0 it is deserialized into Schema.type field. Serialization to YAML/JSON behaves in the same way.

Programmatic access to Schema "type(s)" in 3.1 is provided via Set<String> Schema.getTypes() to be able to support arrays.

In 3.1 Schema.type field is not populated (as bug above is fixed in #1846), and by default Schema.getType() returns null;
since Swagger Core 2.2.6 / Swagger Parser 2.1.8 bind-type=true can be provided as System Property to have Schema.getType() return the value of the single item of set Schema.getTypes() when types has a single element.

Such usage is probably discouraged except in scenarios where the accessed Schema in the OAS document is surely having a single value for type defined, otherwise the additional types would be lost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants