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

StringSchema incorrectly treated as a model #1503

Merged
merged 5 commits into from
Jun 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -679,25 +679,7 @@ object ProtocolGenerator {
polyADTs <- hierarchies.traverse(fromPoly(_, concreteTypes, definitions.value, dtoPackage, supportPackage.toList, defaultPropertyRequirement, components))
elems <- definitionsWithoutPoly.traverse { case (clsName, model) =>
model
.refine { case m: StringSchema => m }(m =>
for {
formattedClsName <- formatTypeName(clsName)
enum <- fromEnum(formattedClsName, m, dtoPackage, components)
model <- fromModel(
NonEmptyList.of(formattedClsName),
m,
List.empty,
concreteTypes,
definitions.value,
dtoPackage,
supportPackage.toList,
defaultPropertyRequirement,
components
)
alias <- modelTypeAlias(clsName, m, components)
} yield enum.orElse(model).getOrElse(alias)
)
.orRefine { case c: ComposedSchema => c }(comp =>
.refine { case c: ComposedSchema => c }(comp =>
for {
formattedClsName <- formatTypeName(clsName)
parents <- extractParents(comp, definitions.value, concreteTypes, dtoPackage, supportPackage.toList, defaultPropertyRequirement, components)
Expand Down Expand Up @@ -739,6 +721,26 @@ object ProtocolGenerator {
alias <- modelTypeAlias(formattedClsName, m, components)
} yield enum.orElse(model).getOrElse(alias)
)
.orRefine { case x: StringSchema => x }(x =>
for {
formattedClsName <- formatTypeName(clsName)
enum <- fromEnum(formattedClsName, x, dtoPackage, components)
model <- fromModel(
NonEmptyList.of(formattedClsName),
x,
List.empty,
concreteTypes,
definitions.value,
dtoPackage,
supportPackage.toList,
defaultPropertyRequirement,
components
)
customTypeName <- SwaggerUtil.customTypeName(x)
(declType, _) <- SwaggerUtil.determineTypeName[L, F](x, Tracker.cloneHistory(x, customTypeName), components)
alias <- typeAlias[L, F](formattedClsName, declType)
} yield enum.orElse(model).getOrElse(alias)
)
.orRefine { case x: IntegerSchema => x }(x =>
for {
formattedClsName <- formatTypeName(clsName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class AliasSpecs extends AnyFreeSpec with Matchers with BeforeAndAfterAll with M
"test alias.foo" - {
"optional body handled with alias param" in {

when(handlerMock.doFoo(java.util.Optional.of(1L), java.util.Optional.of(42L)))
when(handlerMock.doFoo(java.util.Optional.of(1L), java.util.Optional.of("foo"), java.util.Optional.of(42L)))
.thenReturn(CompletableFuture.completedFuture(FooHandler.DoFooResponse.Created(42L)))

val mvcResult = mvc
.perform(
post("/foo?long=1")
post("/foo?long=1&string=foo")
.contentType(MediaType.APPLICATION_JSON)
.content("42")
)
Expand Down
88 changes: 48 additions & 40 deletions modules/sample/src/main/resources/alias.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
swagger: "2.0"
openapi: 3.0.0
info:
title: Whatever
version: 1.0.0
host: localhost:1234
servers:
- url: //localhost:1234
paths:
/foo:
post:
operationId: doFoo
x-jvm-package: foo
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: long
type: integer
format: int64
- in: body
name: body
schema:
$ref: '#/definitions/defLong'
responses:
'201':
description: "Created"
- in: query
name: long
schema:
type: integer
format: int64
- in: query
name: string
schema:
$ref: '#/definitions/defLong'
definitions:
defLong:
type: integer
format: int64
defArrayLong:
type: array
items:
$ref: "#/components/schemas/defString"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/defLong"
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/defLong"
components:
schemas:
defString:
type: string
defLong:
type: integer
format: int64
defArrayArrayLong:
type: array
items:
$ref: '#/definitions/defArrayLong'
propRef:
type: object
required:
- arrayArray
properties:
param:
$ref: "#/definitions/defLong"
array:
$ref: "#/definitions/defArrayLong"
arrayArray:
$ref: "#/definitions/defArrayArrayLong"
defArrayLong:
type: array
items:
type: integer
format: int64
defArrayArrayLong:
type: array
items:
$ref: "#/components/schemas/defArrayLong"
propRef:
type: object
required:
- arrayArray
properties:
param:
$ref: "#/components/schemas/defLong"
array:
$ref: "#/components/schemas/defArrayLong"
arrayArray:
$ref: "#/components/schemas/defArrayArrayLong"