Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ you can focus on implementing the business logic for your service.

We have chosen to focus on [Echo](https://github.com/labstack/echo) as
our default HTTP routing engine, due to its speed and simplicity for the generated
stubs, and [Chi](https://github.com/go-chi/chi), and [Gin](https://github.com/gin-gonic/gin)
have also been added by contributors as additional routers. We chose Echo because
the `Context` object is a mockable interface, and it allows for some advanced
testing.
stubs, and [Chi](https://github.com/go-chi/chi), [Gin](https://github.com/gin-gonic/gin),
and [gorilla/mux](https://github.com/gorilla/mux) have also been added by
contributors as additional routers. We chose Echo because the `Context` object
is a mockable interface, and it allows for some advanced testing.

This package tries to be too simple rather than too generic, so we've made some
design decisions in favor of simplicity, knowing that we can't generate strongly
Expand Down
169 changes: 144 additions & 25 deletions internal/test/schemas/schemas.gen.go

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

15 changes: 14 additions & 1 deletion internal/test/schemas/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,20 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/DeprecatedProperty"

/issues/1051:
get:
operationId: Issue1051
description: |
Multiple media types contain JSON
responses:
'200':
content:
application/vnd.something.v1+json:
schema:
type: object
application/json:
schema:
type: object
components:
schemas:
GenericObject:
Expand Down
10 changes: 8 additions & 2 deletions pkg/codegen/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,18 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini

var typeName string
switch {

// HAL+JSON:
case StringInArray(contentTypeName, contentTypesHalJSON):
typeName = fmt.Sprintf("HALJSON%s", ToCamelCase(responseName))
// JSON:
case StringInArray(contentTypeName, contentTypesJSON) || util.IsMediaTypeJson(contentTypeName):
case "application/json" == contentTypeName:
// if it's the standard application/json
typeName = fmt.Sprintf("JSON%s", ToCamelCase(responseName))
// Vendored JSON
case StringInArray(contentTypeName, contentTypesJSON) || util.IsMediaTypeJson(contentTypeName):
baseTypeName := fmt.Sprintf("%s%s", ToCamelCase(contentTypeName), ToCamelCase(responseName))

typeName = strings.ReplaceAll(baseTypeName, "Json", "JSON")
// YAML:
case StringInArray(contentTypeName, contentTypesYAML):
typeName = fmt.Sprintf("YAML%s", ToCamelCase(responseName))
Expand Down