Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum does not get added when using v3.1 flag #1955

Open
hLittle opened this issue Dec 30, 2024 · 0 comments
Open

Enum does not get added when using v3.1 flag #1955

hLittle opened this issue Dec 30, 2024 · 0 comments

Comments

@hLittle
Copy link

hLittle commented Dec 30, 2024

Describe the bug
Enum values do not get added when using v3.1 flag on 2.0.0-rc4

To Reproduce
Reproduction code:

package main

import (
	"log"
	"net/http"
)

type EnhancementType string // @name EnhancementType

const (
	Foo EnhancementType = "FOO"
	Bar EnhancementType = "BAR"
)

type Enhancement struct {
	EnhancementType EnhancementType `json:"enhancement_type" example:"FOO"`
}

// Enhance - handler for /
// @Summary Example Data
// @Tags         example
// @Accept       json
// @Produce      json
// @Param        enhance  body      Enhancement  true  "Enhancement Request Body"
// @Success      200  {object}  Enhancement
// @Failure      400  {object}  object
// @Failure      404  {object}  object
// @Failure      500  {object}  object
// @Router / [post]
func example(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("{\"enhancement_type\": \"BAR\"}"))
}

func handleRequests() {
	http.HandleFunc("/", example)
	log.Fatal(http.ListenAndServe(":10000", nil))
}

// @title Swagger Example API
// @version 1.0
// @description This is a sample server

// @host localhost:10000
func main() {
	handleRequests()
}

Command:

 swag init -d ./ -g ./main.go -o ./docs --parseDependency --parseInternal --parseDepth 3 --v3.1 --ot yaml,go

Expected behavior
Enum is generated

  EnhancementType:
    enum:
    - FOO
    - BAR
    type: string
    x-enum-varnames:
    - Foo
    - Bar

Actual behavior
Adds x-enum-varnames but not enum:

components:
  schemas:
    main.Enhancement:
      properties:
        enhancement_type:
          $ref: '#/components/schemas/main.EnhancementType'
      type: object
    main.EnhancementType:
      example: FOO
      type: string
      x-enum-varnames:
      - Foo
      - Bar

Your swag version
2.0.0-rc4

Your go version
go version go1.23.2 darwin/arm64

Desktop (please complete the following information):

  • OS: macOS Sonoma
  • Browser: N/A
  • Version: N/A
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

No branches or pull requests

1 participant