Skip to content

Commit

Permalink
Merge pull request #356 from pace/generate-links-struct
Browse files Browse the repository at this point in the history
Generate json api "links" struct when specified in spec
  • Loading branch information
flofuenf authored Oct 4, 2023
2 parents 59f1d9a + 6b1f7a6 commit 15d75b6
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 3 deletions.
11 changes: 11 additions & 0 deletions http/jsonapi/generator/generate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ func (g *Generator) structJSONAPI(prefix string, stmt *jen.Statement, schema *op
fields = append(fields, attrFields...)
}

// add links attribute
links := schema.Properties["links"]
if links != nil {
linksAttr := jen.Id("Links")
err := g.buildTypeStruct(prefix+"Links", linksAttr, links.Value, true)
if err != nil {
return err
}
fields = append(fields, linksAttr)
}

// att meta attribute
meta := schema.Properties["meta"]
if meta != nil {
Expand Down
46 changes: 46 additions & 0 deletions http/jsonapi/generator/internal/articles/open-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,42 @@
"description": "Not found"
}
}
},
"get": {
"tags": [
"Article"
],
"operationId": "getArticleComments",
"summary": "Gets the Article's Comments",
"parameters": [
{
"in": "path",
"name": "uuid",
"required": true,
"schema": {
"type": "string"
},
"description": "Article ID"
}
],
"responses": {
"200": {
"description": "Comments",
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/Comments"
}
}
}
},
"204": {
"description": "No content"
},
"404": {
"description": "Not found"
}
}
}
},
"/api/articles/{uuid}/relationships/inline": {
Expand Down Expand Up @@ -179,6 +215,16 @@
"type": "string",
"format": "uuid"
},
"links": {
"type": "object",
"properties": {
"href": {
"type": "string",
"example": "https://example.com",
"description": "Link to comment"
}
}
},
"attributes": {
"type": "object",
"properties": {
Expand Down
124 changes: 121 additions & 3 deletions http/jsonapi/generator/internal/articles/open-api_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15d75b6

Please sign in to comment.