From 42d3dbdb9a5c80bd5444815c9663aa051743a3a7 Mon Sep 17 00:00:00 2001 From: Parker Mauney Date: Tue, 13 Dec 2022 14:19:48 -0500 Subject: [PATCH] Add failing test for enum collection parameters --- .../springdoc/api/app36/EnumFieldHolder.java | 52 ++++++ .../api/app36/EnumFieldHolderRepository.java | 35 ++++ .../api/app36/SpringDocApp36Test.java | 32 ++++ .../src/test/resources/results/app36.json | 167 ++++++++++++++++++ 4 files changed, 286 insertions(+) create mode 100644 springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolder.java create mode 100644 springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolderRepository.java create mode 100644 springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/SpringDocApp36Test.java create mode 100644 springdoc-openapi-data-rest/src/test/resources/results/app36.json diff --git a/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolder.java b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolder.java new file mode 100644 index 000000000..1354beb6f --- /dev/null +++ b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolder.java @@ -0,0 +1,52 @@ +/* + * + * * Copyright 2019-2022 the original author or 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 + * * + * * https://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 test.org.springdoc.api.app36; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class EnumFieldHolder { + + public enum EnumField { + + FOO, BAR; + + } + + @Id + @GeneratedValue + private Long id; + + private EnumField enumField; + + public Long getId() { + return id; + } + + public EnumField getEnumField() { + return enumField; + } + + public void setEnumField(EnumField enumField) { + this.enumField = enumField; + } + +} diff --git a/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolderRepository.java b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolderRepository.java new file mode 100644 index 000000000..88a2b518d --- /dev/null +++ b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/EnumFieldHolderRepository.java @@ -0,0 +1,35 @@ +/* + * + * * Copyright 2019-2022 the original author or 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 + * * + * * https://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 test.org.springdoc.api.app36; + +import java.util.List; + +import org.springframework.data.repository.Repository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import org.springframework.data.util.Streamable; + +@RepositoryRestResource +public interface EnumFieldHolderRepository extends Repository { + + Streamable findAllByEnumField(@Param("enumField") EnumFieldHolder.EnumField enumField); + + Streamable findAllByEnumFieldIn(@Param("enumFields") List enumFields); + +} diff --git a/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/SpringDocApp36Test.java b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/SpringDocApp36Test.java new file mode 100644 index 000000000..4bef9476f --- /dev/null +++ b/springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app36/SpringDocApp36Test.java @@ -0,0 +1,32 @@ +/* + * + * * Copyright 2019-2022 the original author or 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 + * * + * * https://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 test.org.springdoc.api.app36; + +import test.org.springdoc.api.AbstractSpringDocTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +public class SpringDocApp36Test extends AbstractSpringDocTest { + + @SpringBootApplication + static class SpringDocTestApp { + + } + +} diff --git a/springdoc-openapi-data-rest/src/test/resources/results/app36.json b/springdoc-openapi-data-rest/src/test/resources/results/app36.json new file mode 100644 index 000000000..3aabae473 --- /dev/null +++ b/springdoc-openapi-data-rest/src/test/resources/results/app36.json @@ -0,0 +1,167 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "OpenAPI definition", + "version": "v0" + }, + "servers": [ + { + "url": "http://localhost", + "description": "Generated server url" + } + ], + "paths": { + "/enumFieldHolders/search/findAllByEnumField": { + "get": { + "tags": [ + "enum-field-holder-search-controller" + ], + "operationId": "executeSearch-enumfieldholder-get", + "parameters": [ + { + "name": "enumField", + "in": "query", + "schema": { + "type": "string", + "enum": [ + "FOO", + "BAR" + ] + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/hal+json": { + "schema": { + "$ref": "#/components/schemas/CollectionModelEntityModelEnumFieldHolder" + } + } + } + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/enumFieldHolders/search/findAllByEnumFieldIn": { + "get": { + "tags": [ + "enum-field-holder-search-controller" + ], + "operationId": "executeSearch-enumfieldholder-get_1", + "parameters": [ + { + "name": "enumFields", + "in": "query", + "schema": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "FOO", + "BAR" + ] + } + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/hal+json": { + "schema": { + "$ref": "#/components/schemas/CollectionModelEntityModelEnumFieldHolder" + } + } + } + }, + "404": { + "description": "Not Found" + } + } + } + } + }, + "components": { + "schemas": { + "CollectionModelEntityModelEnumFieldHolder": { + "type": "object", + "properties": { + "_embedded": { + "type": "object", + "properties": { + "enumFieldHolders": { + "type": "array", + "items": { + "$ref": "#/components/schemas/EntityModelEnumFieldHolder" + } + } + } + }, + "_links": { + "$ref": "#/components/schemas/Links" + } + } + }, + "EntityModelEnumFieldHolder": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "enumField": { + "type": "string", + "enum": [ + "FOO", + "BAR" + ] + }, + "_links": { + "$ref": "#/components/schemas/Links" + } + } + }, + "Link": { + "type": "object", + "properties": { + "deprecation": { + "type": "string" + }, + "href": { + "type": "string" + }, + "hreflang": { + "type": "string" + }, + "name": { + "type": "string" + }, + "profile": { + "type": "string" + }, + "templated": { + "type": "boolean" + }, + "title": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "Links": { + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Link" + } + } + } + } +}