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

Swagger definition of the sortBy meta property and the meta and links properties breaks Golang codegen #1027

Open
mikerobski opened this issue Nov 15, 2024 · 1 comment

Comments

@mikerobski
Copy link

When processing the Swagger definition to generate Golang SDK using the Swagger codegen we encountered two issues:

  1. The definition of the sortBy property of the PaginatedMetaDocumented class contains the following definition of the items here:
            items: {
                oneOf: [
                    {
                        type: 'string',
                    },
                    {
                        type: 'string',
                        enum: ['ASC', 'DESC'],
                    },
                ],
            },

The result of the code generation uses item type "Object", which is invalid in Golang and breaks the code.

Replacing this definition with the following works properly by creating Golang type string of strings (SortBy [][]string):

            items: {
                    type: 'string',
            },
  1. The definition of the PaginatedDocumented class contains title for the meta and links properties here:
    @ApiProperty({
        title: 'Pagination Metadata',
        required: true,
    })
    override meta!: PaginatedMetaDocumented<T>

    @ApiProperty({
        title: 'Links to pages',
        required: true,
    })
    override links!: PaginatedLinksDocumented

This forces Swagger document to wrap the type in allOf construct. See the discussion here.

Removing the title from the declaration makes the Swagger definition use direct reference of the types:

    @ApiProperty({
        required: true,
    })
    override meta!: PaginatedMetaDocumented<T>

    @ApiProperty({
        required: true,
    })
    override links!: PaginatedLinksDocumented
@Helveg
Copy link
Collaborator

Helveg commented Dec 3, 2024

Nice analysis of the problem! I think dropping the titles there shouldn't be an issue, but the solution to type sortBy as a string feels like a loss of information. Is there a better Swagger way to express/document that it should be column or column:ASC/column:DESC?

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

2 participants