swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

V1 - SwaggerCompatConverter - Bad mapping in "Contact" object

Open phiz71 opened this issue 4 years ago • 2 comments

Hi, according to the 1.2 version of Swagger specs, info.contact is used for email. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md#513-info-object

However, in the SwaggerCompatConverter, the contact field is put into url https://github.com/swagger-api/swagger-parser/blob/v1/modules/swagger-compat-spec-parser/src/main/java/io/swagger/parser/SwaggerCompatConverter.java#L554-L555

            Contact contact = null;
            if (apiInfo.getContact() != null) {
                contact = new Contact()
                        .url(apiInfo.getContact());
            }

It should be "email".

As a consequence, when I parse this swagger descriptor in version 1.2 with OpenAPIParser:

{
  "apiVersion": "1.2.3",
  "swaggerVersion": "1.2",
  "info": {
    "title": "My title",
    "description": "My description",
    "termsOfServiceUrl": "http://swagger.io/terms/",
    "contact": "[email protected]",
    "license": "Apache 2.0",
    "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html"
  }
...

I get this OpenAPI descriptor:

openapi: 3.0.1
info:
  title: My title
  description: My description
  termsOfService: http://swagger.io/terms/
  contact:
    url: [email protected]
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.2.3
...

which is not valid, since info.contact.url must be in the format of a URL (https://swagger.io/specification/#contact-object)

phiz71 avatar Oct 06 '20 08:10 phiz71

It seems that what I propose is in conflict with LegacyConverterTest.

phiz71 avatar Oct 09 '20 20:10 phiz71

@gracekarina what do you think is the best option ?

  • fix the issue on the v1 branch and update LegacyConverterTest https://github.com/swagger-api/swagger-parser/blob/v1/modules/swagger-compat-spec-parser/src/test/java/io/swagger/converter/LegacyConverterTest.java#L168

or

  • fix the issue on master in SwaggerConverter class. https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java#L504-L506

phiz71 avatar Oct 09 '20 20:10 phiz71