swagger-api / swagger-api/swagger-codegen

Client SDK generation fails when referenced domain contains schema with pattern

Open
#10,119 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names no repository files, tests, or entry points. Start with the minimal OpenAPI YAML containing the externally referenced schema and its pattern, then reproduce C# client generation through the applicable command or entry point. Done means generation succeeds and the pattern constraint is handled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.