Skip to content

generate enum constants#181

Merged
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
dududko:gen-enum-constants
Jun 15, 2020
Merged

generate enum constants#181
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
dududko:gen-enum-constants

Conversation

@dududko
Copy link
Copy Markdown
Contributor

@dududko dududko commented May 7, 2020

Added enum generation by producing constants for each enum value.
It only works if enum is the independent schema.

components:
  schemas:
    MyEnums:
      type: string
      enum:
        - PHONE
        - EMAIL
// MyEnums defines model for MyEnums.
type MyEnums string

// List of MyEnums
const (
        MyEnums_PHONE MyEnums = "PHONE"
        MyEnums_EMAIL MyEnums = "EMAIL"
)

It does not work if the attribute of a schema has the enum type.
Fixes #54

@dududko dududko force-pushed the gen-enum-constants branch from 155bbe8 to eac74e5 Compare June 1, 2020 20:22
@deepmap-marcinr deepmap-marcinr merged commit 43d757f into oapi-codegen:master Jun 15, 2020
@vlastahajek vlastahajek mentioned this pull request Oct 21, 2020
@nabheet
Copy link
Copy Markdown

nabheet commented Nov 18, 2020

It only works if enum is the independent schema.

That is a key phrase here. This will NOT work if the string enum is defined inside object properties. Please ensure that the string enum is a separate schema definition.

adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing Enum Values and validation code

3 participants