swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
777 stars 525 forks source link

swagger-parser-v2-converter convert with error #1602

Open ravitHuber opened 2 years ago

ravitHuber commented 2 years ago

When trying to convert "swagger" : "2.0" to "openapi" : "3.0.1" in Java project using: swaggerConverter.readContents(content, null, options); with options: ParseOptions options = new ParseOptions(); options.setFlatten(true); options.setResolve(true);

using version: '2.0.27'

for the following swagger 2:

{
  "swagger" : "2.0",
  "info" : {
    "description" : "",
    "version" : "1.0"
  },
  "host" : "example.com",
  "basePath" : "/test",
  "schemes" : [ "https" ],
  "security" : [ {
    "API Key" : [ ]
  } ],
  "paths" : 
  ...
  "securityDefinitions" : {
    "API Key" : {
      "description" : "API Key",
      "type" : "apiKey",
      "name" : "KeyId",
      "in" : "header"
    }
  },
...
}

I get this from Json.pretty on the converted result:

{
  "openapi" : "3.0.1",
  "info" : {
    "version" : "1.0"
  },
  "servers" : [ {
    "url" : "https://example.com/test"
  } ],
  "security" : [ {
    "API Key" : [ ]
  } ],
  "paths" : ...
  "components" : {
    "schemas" : { },
    "securitySchemes" : {
      "API Key" : {
        "type" : "apiKey",
        "description" : "API Key",
        "name" : "KeyId",
        "in" : "header"
      }
    }
  },
...,
  "x-original-swagger-version" : "2.0"
}

that issues the following error: "attribute components securitySchemes SecurityScheme name API Key doesn't adhere to regular expression ^[a-zA-Z0-9\ \-_]+$"

ymohdriz commented 2 years ago

Hi @ravitHuber

It's the expected behavior. As per the specification, the allowed characters in the keys are alphanumeric, dot, hyphen, or underscore.

Please find the below description from the specification (https://swagger.io/specification/#components-object) All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.

Thanks, Mohammed