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

Generate spec doesn't include description on model field if the type links to another model #3094

Open
friedrichsenm opened this issue Mar 19, 2024 · 1 comment
Labels
generate spec Related to spec generation from code

Comments

@friedrichsenm
Copy link

Problem statement

If a model or response includes a field whose type is another model. Adding a comment to that field won't result in a description field when running generate spec -m -o swagger.yaml

Steps to reproduce

In this example anotherModel includes a field that references someModel

package go_swagger_example

// This is some model
// swagger:model
type someModel struct {
	// The name of a thing
	Name string `json:"name"`
	// The ID of a thing
	ID int `json:"id"`
}

// This is another model
// swagger:model
type anotherModel struct {
	// The name of another thing
	Name string `json:"name"`
	// This model sometimes includes another model
	SomeModel *someModel `json:"model"`
}

Running swagger generate spec -o swagger.yaml -m produces:

definitions:
    anotherModel:
        description: This is another model
        properties:
            model:
                $ref: '#/definitions/someModel'
            name:
                description: The name of another thing
                type: string
                x-go-name: Name
        type: object
        x-go-package: go-swagger-example
    someModel:
        description: This is some model
        properties:
            id:
                description: The ID of a thing
                format: int64
                type: integer
                x-go-name: ID
            name:
                description: The name of a thing
                type: string
                x-go-name: Name
        type: object
        x-go-package: go-swagger-example
paths: {}
swagger: "2.0"

There is no description on the model field for anotherModel

Environment

swagger version: v0.30.5
go version: 1.21
OS: darwin

@fredbi fredbi added the generate spec Related to spec generation from code label Mar 19, 2024
@yuri-potatoq
Copy link

Looks like when the parser try to set the description from field comment here, there's no function to set description yet.

Because the sectionedParser builder checks if the schemaType is a reference to another here.

I figured it out just by setting the function like that:

sp.setDescription = func(lines []string) {
    ps.Description = joinDropLast(lines)
}

If there is no problem this aproach, i would like to open a PR fixing adding that behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code
Projects
None yet
Development

No branches or pull requests

3 participants