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

Bug: Translating a version 2 specification using Responses with Inline Schema and additionalPropeties: false fails to capture details of response #1552

Closed
fuzails opened this issue Apr 9, 2021 · 2 comments

Comments

@fuzails
Copy link

fuzails commented Apr 9, 2021

In the Java version of the parser you have the following specification:

swagger: '2.0'
info:
  title: Some API
  description: >-
    This is the Some Api
  version: 2.0.0
basePath: /somepath
schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  /somepath:
    get:
      description: >
        my description
      operationId: MyGet
      responses:
        '200':
          $ref: '#/responses/Response'
responses:
  Response:
    description: Response
    schema:
      type: object
      required:
        - Report
      properties:
        Report:
          type: string
      additionalProperties: false

Using OpenAPI api = new OpenAPIParser().readContents(yml, null, new ParseOptions()).getOpenAPI();

results in the response Response having a schema object with no properties. As the properties are ignored as the parser believes there ire additionalProperties when in fact there are none

This can be tracked to a possible issue with io.swagger.models.utils.PropertyModelConverter#modelToProperty lines 25-47. With additionalProperties being false lines 25-47 should not be executed howevere the value additionalProperties: false is instead being translated into an actual io.swagger.models.properties.Property instead of it generating a null object.

@benken-parasoft
Copy link

benken-parasoft commented Nov 11, 2022

I just ran into this except that it doesn't seem to have anything to do with "additionalProperties".

Example:

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;

public class FooTest {

    public static void main(String[] args) {
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        OpenAPIParser parser = new OpenAPIParser();
        SwaggerParseResult result = parser.readContents(
                "swagger: \"2.0\"\n"
                + "info:\n"
                + "  version: \"1.0\"\n"
                + "  title: \"test\"\n"
                + "host: \"foo\"\n"
                + "paths:\n"
                + "  /example:\n"
                + "    get:\n"
                + "      consumes:\n"
                + "        - \"application/json\"\n"
                + "      produces:\n"
                + "        - \"application/json\"\n"
                + "      responses:\n"
                + "        200:\n"
                + "          $ref: \"#/responses/something\"\n"
                + "responses:\n"
                + "  something:\n"
                + "    description: \"my response\"\n"
                + "    schema:\n"
                + "      title: \"my schema\"\n"
                + "      properties:\n"
                + "        foo:\n"
                + "          type: string\n"
                + "", null, options);
        System.out.println("errors: " + result.getMessages());  // no errors
        Schema<?> schema = result.getOpenAPI().getPaths()
                .get("/example").getGet()
                .getResponses().get("200").getContent()
                .get("application/json").getSchema();
        System.out.println("title: " + schema.getTitle());  // found title
        System.out.println("properties: " + schema.getProperties());  // null properties
    }
}

@frantuma
Copy link
Member

Thanks for reporting this. It has been fixed in #1849 (available in latest 2.1.9 release). Please note that both reported errors above were (also) occurring while converting a Swagger / OpenAPI 2.0 into a OpenAPI 3.0 specification, as you are using version 2.x of swagger-parser which supports OpenAPI 3.x and as said Swagger 2.0 via conversion.

Please check v1 branch if your intention is instead to parse/validate/resolve a Swagger / OpenAPI 2.0 spec.

Closing ticket, please reopen if you're still experiencing issues

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