swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

Client SDK generation fails when referenced domain contains schema with pattern #10119

Open jeffreydking opened 4 years ago

jeffreydking commented 4 years ago
Description

Client SDK generation fails when referenced domain contains schema with pattern

If a domain contains an schema like this:

components:
  schemas:
    countryCode:
      description: "An ISO 3166-1 Alpha-2 country code."
      type: 'string'
      pattern: '([A-Z]){2}' # inclusion of this line causes Client SDK generation to fail.
      example: 'US'

and the domain schema is referenced in a API spec like this:

paths:
  /example/path:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: 'https://example.com/path/to/domain#/components/schemas/countryCode'

Client SDK generation will fail with the following error:

Error.There was an error generating the clients csharp code. Please ensure that the definition and all external refs (inc. domains) are valid.

Commenting out the pattern will allow the SDK to generate as expected.

Swagger-codegen version

Whichever version is in current use by SwaggerHub. I assume it is current.

Swagger declaration file content or url

See description.

Command line used for generation

Whatever SwaggerHub uses when selecting the option to generate Client SDKs for an API.

Steps to reproduce

See description.

Related issues/PRs

Not to my knowledge.

Suggest a fix/enhancement

Unknown.

PaddySe commented 4 years ago

It will also work if you use the ECMA 262-format for the pattern, i.e. enclosing it with // (i.e. /([A-Z]){2}/ in your example above).

The Swagger yaml format specification specifies to use the ECMA 262 format, but in their examples in the same documentation they use format you use...