-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remap 'allowableValues' and 'defaultValue' (#148)
to 'enum' and 'default' for schema model.
- Loading branch information
croudet
authored
Feb 18, 2020
1 parent
521b864
commit d2fe214
Showing
2 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
openapi/src/test/groovy/io/micronaut/openapi/visitor/OpenApiOperationParametersSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2017-2019 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.openapi.visitor | ||
|
||
import io.micronaut.annotation.processing.test.AbstractTypeElementSpec | ||
import io.micronaut.http.MediaType | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn | ||
import io.swagger.v3.oas.annotations.media.ArraySchema | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.models.OpenAPI | ||
import io.swagger.v3.oas.models.Operation | ||
|
||
class OpenApiOperationParametersSpec extends AbstractTypeElementSpec { | ||
def setup() { | ||
System.setProperty(AbstractOpenApiVisitor.ATTR_TEST_MODE, "true") | ||
} | ||
|
||
void "test Parameters in Operation"() { | ||
given: | ||
buildBeanDefinition('test.MyBean', ''' | ||
package test; | ||
import io.swagger.v3.oas.annotations.*; | ||
import io.swagger.v3.oas.annotations.parameters.*; | ||
import io.swagger.v3.oas.annotations.responses.*; | ||
import io.swagger.v3.oas.annotations.security.*; | ||
import io.swagger.v3.oas.annotations.media.*; | ||
import io.swagger.v3.oas.annotations.enums.*; | ||
import io.swagger.v3.oas.annotations.links.*; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.*; | ||
import java.util.List; | ||
@Controller("/") | ||
class MyController { | ||
@Get("/") | ||
@Operation(description = "Lists the Pets.", | ||
parameters = { | ||
@Parameter(name = "petType", in = ParameterIn.HEADER, required = true, description = "A pet type", example = "['dog', 'cat']", schema = @Schema(description = "A _Pet_'s type", type = "string", allowableValues = {"dog", "cat", "snake"}, defaultValue = "dog")) | ||
} | ||
) | ||
@ApiResponse(responseCode = "200", description = "Returns a _Pet_.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Pet.class))) | ||
public Pet findPets(String petType) { | ||
return null; | ||
} | ||
} | ||
@Schema(description = "Pet") | ||
class Pet { | ||
@Schema(description = "The name of the pet") | ||
public String name; | ||
} | ||
@javax.inject.Singleton | ||
class MyBean {} | ||
''') | ||
|
||
OpenAPI openAPI = AbstractOpenApiVisitor.testReference | ||
Operation operation = openAPI.paths?.get("/")?.get | ||
|
||
expect: | ||
operation | ||
operation.responses.size() == 1 | ||
operation.responses.'200'.description == 'Returns a _Pet_.' | ||
operation.responses.'200'.content.'application/json'.schema.$ref == '#/components/schemas/Pet' | ||
|
||
operation.parameters | ||
operation.parameters.size() == 1 | ||
operation.parameters[0].name == 'petType' | ||
operation.parameters[0].description == 'A pet type' | ||
operation.parameters[0].schema.description == 'A _Pet_\'s type' | ||
operation.parameters[0].schema.type == 'string' | ||
operation.parameters[0].schema.enum | ||
operation.parameters[0].schema.enum == ["dog", "cat", "snake"] | ||
operation.parameters[0].schema.default == 'dog' | ||
} | ||
} |