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

Properties being ignored on schemas containing allOf #1143

Closed
damapin opened this issue Jul 4, 2019 · 7 comments
Closed

Properties being ignored on schemas containing allOf #1143

damapin opened this issue Jul 4, 2019 · 7 comments

Comments

@damapin
Copy link

damapin commented Jul 4, 2019

Hello.

I'm trying to parse a swagger file which is converted to OpenApi object. It seems to run properly, but when I try to extract properties from complex schemas that use allOf then the properties that are not included in the referenced schema are ignored.

For instance, I have this definition of a request body parameter:

parameters:
        - in: body
          name: request_body
          schema:
              $ref: "#/definitions/identificacion_usuario_aplicacion"
          required: true

The referenced definition looks like this:

identificacion_usuario_aplicacion:
    allOf:
        - $ref: '#/definitions/identificacion_usuario'
    properties:
        aplicacion:
            type: string
            description: some description
            example: some example value

Thus I intend to keep all the properties of identificacion_usuario and add a new aplicacion property to the request body. The problem is that this new property is not parsed by the swagger converter. When I call

OpenApi openApi = new OpenAPIV3Parser().read(swaggerFileLocation);

I get an OpenApi object that seems to be ok, but it's not. After inspecting the OpenApi object I found that components->schemas had a LinkedHashMapEntry with key identificacion_usuario_aplicacion that had as value a ComposedSchema with an allOf Schema set. But, unfortunately, ComposedSchema properties were set to null.
Taking a deep dive into the libraries I think the issue comes from io.swagger.parser.util SwaggerDeserializer.Class contained on swagger-parser-1.0.45.jar. The definition method, lines 771 to 773, calls to allOfModel method:

if(node.get("allOf") != null) {
    return allOfModel(node, location, result);
}

allOfModel method, contained in the same class, receives an object node which contains two children nodes: allOf and properties. The properties child node is ignored in this method, which processes and returns only the allOf child node.
I think the problem is there, but I'm not completely sure of it. And also I'm not completely sure about the way to fix it.

Could you please review the issue.

Thank you very much.

@damapin
Copy link
Author

damapin commented Jul 4, 2019

These two screenshots show how the OpenApi object looks like in my debugger.

image

image

@scottr-ad
Copy link
Contributor

@damapin Does it work if you structure your definition like this?

identificacion_usuario_aplicacion:
    allOf:
        - $ref: '#/definitions/identificacion_usuario'
        - type: object
          properties:
              aplicacion:
                  type: string
                  description: some description
                  example: some example value

@garcle
Copy link

garcle commented Sep 25, 2019

identificacion_usuario_aplicacion:
    allOf:
        - $ref: '#/definitions/identificacion_usuario'
        - type: object
        - properties:
              aplicacion:
                  type: string
                  description: some description
                  example: some example value

you need the - in front of properties`

@scottr-ad
Copy link
Contributor

@garcle no, that is incorrect. That would be an allOf list of 3 separate things - i) the $ref, ii) type: object, and iii) an isolated list of properties.
In YAML format, the version I posted is correct, as the indentation causes the properties section to be considered part of the type: object definition.

@mvmn
Copy link

mvmn commented Oct 10, 2019

I have exactly the same issue with Azure model from https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/redis/resource-manager/Microsoft.Cache/stable/2018-03-01/redis.json

For example, RedisResource contains properties and allOf

 "RedisResource": {
      "properties": {
        "properties": {
          "x-ms-client-flatten": true,
          "$ref": "#/definitions/RedisProperties",
          "description": "Redis cache properties."
        },
        "zones": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "A list of availability zones denoting where the resource needs to come from."
        }
      },
      "required": [
        "properties"
      ],
      "allOf": [
        {
          "$ref": "#/definitions/TrackedResource"
        }
      ],
      "description": "A single Redis item in List or Get Operation."
    }

Using swagger-codegen that uses swagger-parser results in RedisResource missing all of it's properties except the ones inherited from definitions/TrackedResource.

Note: in case of RedisResource, there is a property that is actually called "properties" - this is just the name of that property, do not let that confuse you.

Also if I use this model in Swagger UI at swagger.io - the model is generated correctly for Swagger UI:
https://i.postimg.cc/C5MP3KfW/Screen-Shot-2019-10-10-at-14-39-55.png

@mvmn
Copy link

mvmn commented Oct 10, 2019

This is .md file generated for RedisResource by swagger-codegen (that uses swagger-parser):

# RedisResource

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **String** | Resource ID. |  [optional]
**name** | **String** | Resource name. |  [optional]
**type** | **String** | Resource type. |  [optional]

All those properties are inherited from TrackedResource.
It's own properties named "properties" and "zones" are missing.

Same issue in generated code.

There is a clear difference here between Swagger UI and swagger-codegen (and thus swagger-parser) results, and it seems to be pretty clear that swagger-parser has a bug of ignoring "properties" section for any model having "allOf".

frantuma added a commit to swagger-api/swagger-core that referenced this issue Oct 28, 2019
gracekarina added a commit to swagger-api/swagger-codegen that referenced this issue Nov 2, 2019
frantuma added a commit to swagger-api/swagger-core that referenced this issue Nov 12, 2019
frantuma added a commit to swagger-api/swagger-codegen that referenced this issue Nov 12, 2019
frantuma added a commit that referenced this issue Nov 12, 2019
refs - issue #1143 - changes to support properties in ComposedModel
frantuma added a commit that referenced this issue Nov 12, 2019
refs - issue #1143 - changes in converter to support properties in Composed Model
frantuma added a commit to swagger-api/swagger-codegen that referenced this issue Nov 12, 2019
@frantuma
Copy link
Member

fixed in #1240, #1241 and swagger-api/swagger-codegen#9827

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

5 participants