swagger-api / swagger-api/swagger-codegen

[swagger 2.0][go server] validate enum function is not generated for 2-dimensional array

Open
#10,258 0 comments 0 reactions 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

This yaml specification generates validateTestItemsEnum() correctly.

definitions:
  TestObject:
    type: object
    properties:
      test:
        type: array
        items:
          type: string
          enum: [AA, BB, CC]

But in case of 2-dimensional array, the validate function is not generated so that build error occurs.

m.validateTest2ItemsEnum undefined (type *TestObject has no field or method validateTest2ItemsEnum)
definitions:
  TestObject:
    type: object
    properties:
      test:
        type: array
        items:
          type: array
          items:
            type: string
            enum: [AA, BB, CC]

Of course, swagger validator does not show any errors on that.

Swagger-codegen version
version: v0.21.0
commit: 7c0fc3ee340f9d99d85573bc54a57e303a639692
Swagger declaration file content or url
Command line used for generation

swagger -q generate server --exclude-main --spec-...

Steps to reproduce
  1. Add array of 'string array' in yaml file and define enum values for the 'string array'.
  2. Generate code by swagger codegen.
  3. codegen is done with success but build error occurs because there's no enum validation function.
Related issues/PRs
Suggest a fix/enhancement

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

Start with the swagger -q generate server entry point and the Swagger 2.0 Go server generation path, using the two YAML examples in the issue to reproduce the missing validation method. Trace enum validation generation for nested arrays and confirm the generated server builds successfully with a two-dimensional string enum array.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.