├── .gitignore ├── geronimo-openapi-impl └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ ├── services │ │ │ ├── javax.enterprise.inject.spi.Extension │ │ │ ├── org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension │ │ │ └── org.eclipse.microprofile.openapi.spi.OASFactoryResolver │ │ │ └── beans.xml │ └── java │ │ └── org │ │ └── apache │ │ └── geronimo │ │ └── microprofile │ │ └── openapi │ │ ├── impl │ │ ├── model │ │ │ ├── APIMap.java │ │ │ ├── ReferenceImpl.java │ │ │ ├── ContentImpl.java │ │ │ ├── SecurityRequirementImpl.java │ │ │ ├── DiscriminatorImpl.java │ │ │ ├── ExtensibleImpl.java │ │ │ ├── PathsImpl.java │ │ │ ├── ScopesImpl.java │ │ │ ├── LicenseImpl.java │ │ │ ├── ServerVariablesImpl.java │ │ │ ├── CallbackImpl.java │ │ │ ├── ContactImpl.java │ │ │ ├── ExternalDocumentationImpl.java │ │ │ ├── APIResponsesImpl.java │ │ │ ├── OAuthFlowImpl.java │ │ │ ├── ServerImpl.java │ │ │ ├── RequestBodyImpl.java │ │ │ ├── OAuthFlowsImpl.java │ │ │ ├── XMLImpl.java │ │ │ ├── ServerVariableImpl.java │ │ │ ├── TagImpl.java │ │ │ ├── ExampleImpl.java │ │ │ ├── InfoImpl.java │ │ │ ├── EncodingImpl.java │ │ │ ├── MediaTypeImpl.java │ │ │ ├── codec │ │ │ │ ├── Deserializers.java │ │ │ │ └── Serializers.java │ │ │ ├── APIResponseImpl.java │ │ │ ├── LinkImpl.java │ │ │ ├── SecuritySchemeImpl.java │ │ │ ├── OpenAPIImpl.java │ │ │ └── HeaderImpl.java │ │ ├── processor │ │ │ ├── AnnotatedTypeElement.java │ │ │ ├── AnnotatedMethodElement.java │ │ │ ├── reflect │ │ │ │ ├── FieldElement.java │ │ │ │ ├── ClassElement.java │ │ │ │ └── MethodElement.java │ │ │ └── spi │ │ │ │ └── NamingStrategy.java │ │ └── loader │ │ │ ├── DefaultLoader.java │ │ │ └── ApiBindings.java │ │ ├── config │ │ ├── GeronimoOpenAPIConfig.java │ │ ├── OpenAPIConfigMpConfigImpl.java │ │ ├── PrefixedConfig.java │ │ └── DefaultOpenAPIConfig.java │ │ ├── jaxrs │ │ ├── OpenAPIEndpoint.java │ │ ├── BaseOpenAPIYamlBodyWriter.java │ │ ├── JacksonOpenAPIYamlBodyWriter.java │ │ └── OpenAPIFilter.java │ │ └── cxf │ │ └── CxfForceSetup.java │ └── test │ ├── resources │ ├── META-INF │ │ ├── services │ │ │ ├── org.jboss.arquillian.core.spi.LoadableExtension │ │ │ └── org.eclipse.microprofile.config.spi.ConfigSourceProvider │ │ └── persistence.xml │ └── arquillian.xml │ └── java │ └── org │ └── apache │ └── geronimo │ └── microprofile │ └── openapi │ ├── openjpa │ ├── Entity2.java │ └── Entity1.java │ ├── impl │ ├── model │ │ └── OpenAPIImplTest.java │ └── serialization │ │ └── SerializationTest.java │ └── test │ ├── TckMetaInfBugWorkaround.java │ ├── ArquillianSetup.java │ └── YamlAnswerTest.java ├── geronimo-openapi-maven-plugin ├── src │ ├── it │ │ └── generation-test │ │ │ ├── verify.bsh │ │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── test │ │ │ │ ├── SomeEndpoint.java │ │ │ │ └── MyApp.java │ │ │ └── pom.xml │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── geronimo │ │ └── microprofile │ │ └── openapi │ │ └── mojo │ │ └── OpenAPIMojoTest.java └── pom.xml └── README.adoc /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | target 4 | src/test/java/io/* 5 | src/test/java/org/apache/cxf* 6 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension 2 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension: -------------------------------------------------------------------------------- 1 | org.apache.geronimo.microprofile.openapi.test.ArquillianSetup 2 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/resources/META-INF/services/org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension: -------------------------------------------------------------------------------- 1 | org.apache.geronimo.microprofile.openapi.cxf.CxfForceSetup 2 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider: -------------------------------------------------------------------------------- 1 | org.apache.geronimo.microprofile.openapi.test.TckMetaInfBugWorkaround 2 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/resources/META-INF/services/org.eclipse.microprofile.openapi.spi.OASFactoryResolver: -------------------------------------------------------------------------------- 1 | org.apache.geronimo.microprofile.openapi.impl.resolver.OASFactoryResolverImpl 2 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/src/it/generation-test/verify.bsh: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | File generated = new File( basedir, "target/classes/META-INF/resources/openapi.json" ); 4 | 5 | if ( !generated.isFile() ) 6 | { 7 | throw new FileNotFoundException( "Could not find generated OpenAPI definition: " + file ); 8 | } 9 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/APIMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2006-2019 Talend Inc. - www.talend.com 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.geronimo.microprofile.openapi.impl.model; 17 | 18 | import java.util.LinkedHashMap; 19 | 20 | public class APIMap extends LinkedHashMap { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/AnnotatedTypeElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor; 18 | 19 | import java.lang.reflect.AnnotatedElement; 20 | import java.lang.reflect.Type; 21 | 22 | public interface AnnotatedTypeElement extends AnnotatedElement { 23 | 24 | Type getType(); 25 | } 26 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/src/it/generation-test/src/main/java/com/test/SomeEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.test; 18 | 19 | import javax.ws.rs.GET; 20 | import javax.ws.rs.Path; 21 | import javax.ws.rs.PathParam; 22 | 23 | @Path("/endpoint") 24 | public class SomeEndpoint { 25 | 26 | @GET 27 | public String hello(@PathParam("id") int id) { 28 | return "hi!"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/openjpa/Entity2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.openjpa; 18 | 19 | import javax.persistence.Entity; 20 | import javax.persistence.Id; 21 | import javax.persistence.ManyToOne; 22 | 23 | @Entity 24 | public class Entity2 { 25 | @Id 26 | public long id; 27 | 28 | @ManyToOne 29 | public Entity1 ref; 30 | } 31 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/src/it/generation-test/src/main/java/com/test/MyApp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.test; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | @javax.ws.rs.ApplicationPath("resources") 23 | public class MyApp extends javax.ws.rs.core.Application { 24 | 25 | @Override 26 | public Set> getClasses() { 27 | Set> classes = new HashSet<>(); 28 | classes.add(SomeEndpoint.class); 29 | return classes; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/AnnotatedMethodElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor; 18 | 19 | import java.lang.reflect.AnnotatedElement; 20 | import java.lang.reflect.Type; 21 | 22 | public interface AnnotatedMethodElement extends AnnotatedElement { 23 | String getName(); 24 | 25 | Type getReturnType(); 26 | 27 | Class getDeclaringClass(); 28 | 29 | AnnotatedTypeElement[] getParameters(); 30 | } 31 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/config/GeronimoOpenAPIConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.config; 18 | 19 | @FunctionalInterface 20 | public interface GeronimoOpenAPIConfig { 21 | 22 | String read(String value, String def); 23 | 24 | static GeronimoOpenAPIConfig create() { 25 | try { 26 | return new PrefixedConfig(new OpenAPIConfigMpConfigImpl()); 27 | } catch (final NoClassDefFoundError | ExceptionInInitializerError cnfe) { 28 | return new PrefixedConfig(new DefaultOpenAPIConfig()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/config/OpenAPIConfigMpConfigImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.config; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | 21 | import org.eclipse.microprofile.config.Config; 22 | import org.eclipse.microprofile.config.ConfigProvider; 23 | 24 | @Vetoed 25 | class OpenAPIConfigMpConfigImpl implements GeronimoOpenAPIConfig { 26 | private final Config config; 27 | 28 | OpenAPIConfigMpConfigImpl() { 29 | config = ConfigProvider.getConfig(); 30 | } 31 | 32 | @Override 33 | public String read(final String key, final String def) { 34 | return config.getOptionalValue(key, String.class).orElse(def); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/config/PrefixedConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.config; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | 21 | @Vetoed 22 | class PrefixedConfig implements GeronimoOpenAPIConfig { 23 | 24 | private final GeronimoOpenAPIConfig delegate; 25 | 26 | PrefixedConfig(final GeronimoOpenAPIConfig geronimoOpenAPIConfig) { 27 | this.delegate = geronimoOpenAPIConfig; 28 | } 29 | 30 | @Override 31 | public String read(final String value, final String def) { 32 | if (value.startsWith("mp.")) { 33 | return delegate.read(value, def); 34 | } 35 | return delegate.read("geronimo.openapi." + value, def); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/jaxrs/OpenAPIEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.jaxrs; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.WebApplicationException; 23 | import javax.ws.rs.core.Response; 24 | 25 | import org.eclipse.microprofile.openapi.models.OpenAPI; 26 | 27 | // just here to ensure an app is deployed (depends the container scanning/config otherwise) 28 | @Path("openapi") 29 | @ApplicationScoped 30 | public class OpenAPIEndpoint { 31 | @GET 32 | public OpenAPI get() { // filter should handle it 33 | throw new WebApplicationException(Response.Status.BAD_REQUEST); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 25 | 26 | org.apache.geronimo.microprofile.openapi.openjpa.Entity1 27 | org.apache.geronimo.microprofile.openapi.openjpa.Entity2 28 | true 29 | 30 | 31 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/model/OpenAPIImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertNull; 21 | 22 | import org.junit.Test; 23 | 24 | public class OpenAPIImplTest { 25 | @Test 26 | public void duplicatedTags() { 27 | final OpenAPIImpl openAPI = new OpenAPIImpl(); 28 | assertNull(openAPI.getTags()); 29 | openAPI.addTag(new TagImpl().name("foo")); 30 | assertEquals(1, openAPI.getTags().size()); 31 | openAPI.addTag(new TagImpl().name("foo")); 32 | assertEquals(1, openAPI.getTags().size()); 33 | openAPI.addTag(new TagImpl().name("bar")); 34 | assertEquals(2, openAPI.getTags().size()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Geronimo Microprofile OpenAPI 2 | 3 | == Implementation 4 | 5 | === Artifact 6 | 7 | [source,xml] 8 | ---- 9 | 10 | org.apache.geronimo 11 | geronimo-openapi 12 | ${openapi.version} 13 | 14 | ---- 15 | 16 | === Dependencies 17 | 18 | 1. JAX-RS+Servlet 19 | 2. CDI (optional if used as a library) 20 | 3. JSONB (for JSON support) 21 | 4. Jackson+YAML extension (for YAML support) 22 | 23 | == Maven Plugin 24 | 25 | You can define the maven plugin to generate at build time the `openapi.json` file. 26 | Then the runtime is able to load it directly and merge it with the current runtime. 27 | The big advantage is to be able to use it without the runtime for documentation purposes. 28 | 29 | Here is how to define it: 30 | 31 | [source,xml] 32 | ---- 33 | 34 | org.apache.geronimo 35 | geronimo-openapi-maven-plugin 36 | ${openapi.version} 37 | 38 | 39 | generate-openapi.json 40 | 41 | openapi.json 42 | 43 | 44 | com.test.MyApp 45 | 46 | com.test.SomeEndpoint 47 | com.test.SomeOtherEndpoint 48 | 49 | 50 | 1 51 | My Title 52 | Bla Bla 53 | 54 | 55 | 56 | 57 | 58 | ---- 59 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ReferenceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import javax.enterprise.inject.Vetoed; 20 | import javax.json.bind.annotation.JsonbProperty; 21 | 22 | import org.eclipse.microprofile.openapi.models.Reference; 23 | 24 | @Vetoed 25 | public class ReferenceImpl implements Reference { 26 | 27 | private String _ref; 28 | 29 | @Override 30 | @JsonbProperty("$ref") 31 | public String getRef() { 32 | return _ref; 33 | } 34 | 35 | @Override 36 | @JsonbProperty("$ref") 37 | public void setRef(final String _ref) { 38 | this._ref = _ref; 39 | } 40 | 41 | @Override 42 | public Reference ref(final String _ref) { 43 | setRef(_ref); 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/resources/arquillian.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | Local 24 | target/meecrowave/temp 25 | 26 | bsh, 27 | jcip, 28 | nimbus, 29 | org.osgi, 30 | json, 31 | arquillian, 32 | microprofile-, 33 | tagsoup, 34 | rest-assured, 35 | httpmime, 36 | xml-path, 37 | jackson-dataformat-yaml, 38 | java-hamcrest, 39 | snakeyaml 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/jaxrs/BaseOpenAPIYamlBodyWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.jaxrs; 18 | 19 | import java.lang.annotation.Annotation; 20 | import java.lang.reflect.Type; 21 | 22 | import javax.ws.rs.core.MediaType; 23 | import javax.ws.rs.ext.MessageBodyWriter; 24 | 25 | // potential base to use snakeyaml or another serializer 26 | public abstract class BaseOpenAPIYamlBodyWriter implements MessageBodyWriter { 27 | @Override 28 | public boolean isWriteable(final Class type, final Type genericType, 29 | final Annotation[] annotations, final MediaType mediaType) { 30 | return type.getName().startsWith("org.apache.geronimo.microprofile.openapi.impl.model") || 31 | type.getName().startsWith("org.eclipse.microprofile.openapi.models"); 32 | } 33 | 34 | @Override 35 | public long getSize(final T t, final Class type, final Type genericType, 36 | final Annotation[] annotations, final MediaType mediaType) { 37 | return -1; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ContentImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | 24 | import org.eclipse.microprofile.openapi.models.media.Content; 25 | import org.eclipse.microprofile.openapi.models.media.MediaType; 26 | 27 | @Vetoed 28 | public class ContentImpl extends APIMap implements Content { 29 | 30 | @Override 31 | public Content addMediaType(final String name, final MediaType item) { 32 | if (item != null) { 33 | super.put(name, item); 34 | } 35 | return this; 36 | } 37 | 38 | @Override 39 | public void removeMediaType(final String name) { 40 | remove(name); 41 | } 42 | 43 | @Override 44 | public Map getMediaTypes() { 45 | return new LinkedHashMap<>(this); 46 | } 47 | 48 | @Override 49 | public void setMediaTypes(final Map mediaTypes) { 50 | clear(); 51 | putAll(mediaTypes); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/reflect/FieldElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor.reflect; 18 | 19 | import org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedTypeElement; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Field; 23 | import java.lang.reflect.Type; 24 | 25 | public class FieldElement implements AnnotatedTypeElement { 26 | private final Field delegate; 27 | private Annotation[] annotations; 28 | 29 | public FieldElement(final Field delegate) { 30 | this.delegate = delegate; 31 | } 32 | 33 | @Override 34 | public T getAnnotation(final Class annotationClass) { 35 | return delegate.getAnnotation(annotationClass); 36 | } 37 | 38 | @Override 39 | public Annotation[] getAnnotations() { 40 | return delegate.getAnnotations(); 41 | } 42 | 43 | @Override 44 | public Annotation[] getDeclaredAnnotations() { 45 | return delegate.getDeclaredAnnotations(); 46 | } 47 | 48 | @Override 49 | public Type getType() { 50 | return delegate.getGenericType(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/src/it/generation-test/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | org.apache.geronimo.test 5 | geronimo-openapi-generation-test 6 | 1.0 7 | jar 8 | 9 | 10 | 11 | org.apache.maven.plugins 12 | maven-compiler-plugin 13 | 3.8.0 14 | 15 | 1.8 16 | 1.8 17 | 18 | 19 | 20 | org.apache.geronimo 21 | geronimo-openapi-maven-plugin 22 | @project.version@ 23 | 24 | 25 | generate-openapi.json 26 | 27 | openapi.json 28 | 29 | 30 | com.test.MyApp 31 | 32 | com.test.SomeEndpoint 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | jakarta.ws.rs 43 | jakarta.ws.rs-api 44 | 2.1.4 45 | 46 | 47 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/config/DefaultOpenAPIConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.config; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | import java.util.Properties; 24 | 25 | import javax.enterprise.inject.Vetoed; 26 | 27 | @Vetoed 28 | class DefaultOpenAPIConfig implements GeronimoOpenAPIConfig { 29 | private final Map configuration = new HashMap<>(); 30 | 31 | DefaultOpenAPIConfig() { 32 | System.getProperties().stringPropertyNames() 33 | .forEach(k -> configuration.put(k, System.getProperty(k))); 34 | try (final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/geronimo/microprofile/opentracing.properties")) { 35 | if (stream != null) { 36 | final Properties properties = new Properties(); 37 | properties.load(stream); 38 | properties.stringPropertyNames().forEach(k -> configuration.put(k, properties.getProperty(k))); 39 | } 40 | } catch (final IOException e) { 41 | throw new IllegalStateException(e); 42 | } 43 | } 44 | 45 | @Override 46 | public String read(final String value, final String def) { 47 | return configuration.getOrDefault(value, def); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/openjpa/Entity1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.openjpa; 18 | 19 | import java.io.Serializable; 20 | import java.util.Date; 21 | import java.util.List; 22 | 23 | import javax.persistence.Column; 24 | import javax.persistence.Entity; 25 | import javax.persistence.Id; 26 | import javax.persistence.OneToMany; 27 | 28 | @Entity 29 | public class Entity1 implements Serializable { 30 | @Id 31 | private long id; 32 | 33 | @Column(name = "db_string") 34 | private String string; 35 | private Date date; 36 | 37 | @OneToMany 38 | private List relationship; 39 | 40 | public Entity1() { 41 | // no-op 42 | } 43 | 44 | public Entity1(final long id, final String string, final Date date) { 45 | this.id = id; 46 | this.string = string; 47 | this.date = date; 48 | } 49 | 50 | public long getId() { 51 | return id; 52 | } 53 | 54 | public void setId(final long id) { 55 | this.id = id; 56 | } 57 | 58 | public String getString() { 59 | return string; 60 | } 61 | 62 | public void setString(final String string) { 63 | this.string = string; 64 | } 65 | 66 | public Date getDate() { 67 | return date; 68 | } 69 | 70 | public void setDate(Date date) { 71 | this.date = date; 72 | } 73 | 74 | public List getRelationship() { 75 | return relationship; 76 | } 77 | 78 | public void setRelationship(final List relationship) { 79 | this.relationship = relationship; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/cxf/CxfForceSetup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.cxf; 18 | 19 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; 20 | 21 | import java.util.logging.Logger; 22 | 23 | import javax.enterprise.inject.Vetoed; 24 | import javax.enterprise.inject.spi.CDI; 25 | 26 | import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; 27 | import org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension; 28 | import org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension; 29 | import org.apache.geronimo.microprofile.openapi.jaxrs.JacksonOpenAPIYamlBodyWriter; 30 | import org.apache.geronimo.microprofile.openapi.jaxrs.OpenAPIFilter; 31 | 32 | @Vetoed 33 | public class CxfForceSetup implements JAXRSServerFactoryCustomizationExtension { 34 | @Override 35 | public void customize(final JAXRSServerFactoryBean bean) { 36 | if (bean.getProviders().stream().anyMatch(OpenAPIFilter.class::isInstance)) { // default app, nothing to do 37 | return; 38 | } 39 | final CDI current = CDI.current(); 40 | bean.setProvider(current.select(OpenAPIFilter.class).get()); 41 | try { 42 | if (current.select(GeronimoOpenAPIExtension.class).get().getDefaultMediaType().equals(APPLICATION_JSON_TYPE)) { 43 | return; 44 | } 45 | bean.setProvider(current.select(JacksonOpenAPIYamlBodyWriter.class).get()); 46 | } catch (final NoClassDefFoundError | RuntimeException cne) { 47 | Logger.getLogger(CxfForceSetup.class.getName()).warning(cne.getMessage()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/SecurityRequirementImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import static java.util.Collections.emptyList; 20 | import static java.util.Collections.singletonList; 21 | 22 | import java.util.LinkedHashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | import javax.enterprise.inject.Vetoed; 27 | 28 | import org.eclipse.microprofile.openapi.models.security.SecurityRequirement; 29 | 30 | @Vetoed 31 | public class SecurityRequirementImpl extends APIMap> implements SecurityRequirement { 32 | @Override 33 | public SecurityRequirement addScheme(final String securitySchemeName, final String scope) { 34 | return addScheme(securitySchemeName, scope == null ? emptyList() : singletonList(scope)); 35 | } 36 | 37 | @Override 38 | public SecurityRequirement addScheme(final String securitySchemeName, final List scopes) { 39 | super.put(securitySchemeName, scopes == null ? emptyList() : scopes); 40 | return this; 41 | } 42 | 43 | @Override 44 | public SecurityRequirement addScheme(final String securitySchemeName) { 45 | return addScheme(securitySchemeName, emptyList()); 46 | } 47 | 48 | @Override 49 | public void removeScheme(final String securitySchemeName) { 50 | remove(securitySchemeName); 51 | } 52 | 53 | @Override 54 | public Map> getSchemes() { 55 | return new LinkedHashMap<>(this); 56 | } 57 | 58 | @Override 59 | public void setSchemes(final Map> items) { 60 | clear(); 61 | putAll(items); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/DiscriminatorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | 24 | import org.eclipse.microprofile.openapi.models.media.Discriminator; 25 | 26 | @Vetoed 27 | public class DiscriminatorImpl implements Discriminator { 28 | 29 | private Map _mapping; 30 | 31 | private String _propertyName; 32 | 33 | @Override 34 | public Map getMapping() { 35 | return _mapping; 36 | } 37 | 38 | @Override 39 | public void setMapping(final Map _mapping) { 40 | this._mapping = _mapping; 41 | } 42 | 43 | @Override 44 | public Discriminator mapping(final Map _mapping) { 45 | setMapping(_mapping); 46 | return this; 47 | } 48 | 49 | @Override 50 | public Discriminator addMapping(final String key, final String _mapping) { 51 | if (_mapping != null) { 52 | (this._mapping = this._mapping == null ? new LinkedHashMap<>() : this._mapping).put(key, _mapping); 53 | } 54 | return this; 55 | } 56 | 57 | @Override 58 | public void removeMapping(final String name) { 59 | _mapping.remove(name); 60 | } 61 | 62 | @Override 63 | public String getPropertyName() { 64 | return _propertyName; 65 | } 66 | 67 | @Override 68 | public void setPropertyName(final String _propertyName) { 69 | this._propertyName = _propertyName; 70 | } 71 | 72 | @Override 73 | public Discriminator propertyName(final String _propertyName) { 74 | setPropertyName(_propertyName); 75 | return this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/test/TckMetaInfBugWorkaround.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.test; 18 | 19 | import static java.util.Collections.emptyList; 20 | import static java.util.Collections.singletonList; 21 | 22 | import java.io.File; 23 | import java.net.MalformedURLException; 24 | 25 | import org.apache.catalina.Context; 26 | import org.apache.catalina.loader.ParallelWebappClassLoader; 27 | import org.apache.geronimo.config.configsource.PropertyFileConfigSource; 28 | import org.eclipse.microprofile.config.spi.ConfigSource; 29 | import org.eclipse.microprofile.config.spi.ConfigSourceProvider; 30 | 31 | // tck puts config in META-INF of wars and not of jars or WEB-INF so it can't work OOTB 32 | public class TckMetaInfBugWorkaround implements ConfigSourceProvider { 33 | @Override 34 | public Iterable getConfigSources(final ClassLoader classLoader) { 35 | final ConfigSource source = create(classLoader); 36 | return source == null ? emptyList() : singletonList(source); 37 | } 38 | 39 | private ConfigSource create(final ClassLoader classLoader) { 40 | if (classLoader instanceof ParallelWebappClassLoader) { 41 | final Context context = ParallelWebappClassLoader.class.cast(classLoader) 42 | .getResources() 43 | .getContext(); 44 | final File config = new File(new File(context.getCatalinaBase(), "webapps/" + context.getDocBase()), "META-INF/microprofile-config.properties"); 45 | try { 46 | return config.exists() ? new PropertyFileConfigSource(config.toURI().toURL()) : null; 47 | } catch (final MalformedURLException e) { 48 | throw new IllegalStateException(e); 49 | } 50 | } 51 | return null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ExtensibleImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | 23 | import javax.enterprise.inject.Vetoed; 24 | import javax.json.bind.annotation.JsonbTransient; 25 | 26 | import org.eclipse.microprofile.openapi.models.Extensible; 27 | 28 | @Vetoed 29 | public class ExtensibleImpl> implements Extensible { 30 | 31 | private Map _extensions; 32 | 33 | @Override 34 | @JsonbTransient 35 | public Map getExtensions() { 36 | return _extensions; 37 | } 38 | 39 | @Override 40 | public T addExtension(final String key, final Object _extensions) { 41 | if (_extensions == null) { 42 | return (T) this; 43 | } 44 | (this._extensions = this._extensions == null ? new LinkedHashMap<>() : this._extensions) 45 | .put((key.startsWith("x-") ? key : ("x-" + key)), _extensions); 46 | return (T) this; 47 | } 48 | 49 | @Override 50 | public void removeExtension(final String name) { 51 | _extensions.remove(name); 52 | } 53 | 54 | @Override 55 | public void setExtensions(final Map _extensions) { 56 | this._extensions = _extensions; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { 62 | return true; 63 | } 64 | if (o == null || getClass() != o.getClass()) { 65 | return false; 66 | } 67 | return Objects.equals(_extensions, ExtensibleImpl.class.cast(o)._extensions); 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return Objects.hash(_extensions); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/PathsImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.PathItem; 27 | import org.eclipse.microprofile.openapi.models.Paths; 28 | 29 | @Vetoed 30 | public class PathsImpl extends APIMap implements Paths { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | @Override 35 | @JsonbTransient 36 | public Map getExtensions() { 37 | return _extensible.getExtensions(); 38 | } 39 | 40 | @Override 41 | public void setExtensions(final Map extensions) { 42 | _extensible.setExtensions(extensions); 43 | } 44 | 45 | @Override 46 | public Paths addExtension(final String name, final Object value) { 47 | _extensible.addExtension(name, value); 48 | return this; 49 | } 50 | 51 | @Override 52 | public void removeExtension(final String name) { 53 | _extensible.removeExtension(name); 54 | } 55 | 56 | @Override 57 | public Paths addPathItem(final String name, final PathItem item) { 58 | if (item != null) { 59 | super.put(name, item); 60 | } 61 | return this; 62 | } 63 | 64 | @Override 65 | public void removePathItem(final String name) { 66 | remove(name); 67 | } 68 | 69 | @Override 70 | public Map getPathItems() { 71 | return new LinkedHashMap<>(this); 72 | } 73 | 74 | @Override 75 | public void setPathItems(final Map items) { 76 | clear(); 77 | putAll(items); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ScopesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.security.Scopes; 27 | 28 | @Vetoed 29 | public class ScopesImpl extends APIMap implements Scopes { 30 | 31 | private Extensible _extensible = new ExtensibleImpl(); 32 | 33 | @Override 34 | @JsonbTransient 35 | public Map getExtensions() { 36 | return _extensible.getExtensions(); 37 | } 38 | 39 | @Override 40 | public void setExtensions(final Map extensions) { 41 | _extensible.setExtensions(extensions); 42 | } 43 | 44 | @Override 45 | public Scopes addExtension(final String name, final Object value) { 46 | _extensible.addExtension(name, value); 47 | return this; 48 | } 49 | 50 | @Override 51 | public void removeExtension(final String name) { 52 | _extensible.removeExtension(name); 53 | } 54 | 55 | @Override 56 | public void removeScope(final String scope) { 57 | remove(scope); 58 | } 59 | 60 | @Override 61 | public Map getScopes() { 62 | return new LinkedHashMap<>(this); 63 | } 64 | 65 | @Override 66 | public void setScopes(final Map items) { 67 | clear(); 68 | putAll(items); 69 | } 70 | 71 | @Override 72 | public Scopes addScope(final String name, final String item) { 73 | super.put(name, item); 74 | return this; 75 | } 76 | 77 | public Scopes addString(final String name, final String item) { 78 | return addScope(name, item); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/LicenseImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.info.License; 26 | 27 | @Vetoed 28 | public class LicenseImpl implements License { 29 | 30 | private Extensible _extensible = new ExtensibleImpl(); 31 | 32 | private String _name; 33 | 34 | private String _url; 35 | 36 | @Override 37 | @JsonbTransient 38 | public Map getExtensions() { 39 | return _extensible.getExtensions(); 40 | } 41 | 42 | @Override 43 | public void setExtensions(final Map extensions) { 44 | _extensible.setExtensions(extensions); 45 | } 46 | 47 | @Override 48 | public License addExtension(final String name, final Object value) { 49 | _extensible.addExtension(name, value); 50 | return this; 51 | } 52 | 53 | @Override 54 | public void removeExtension(final String name) { 55 | _extensible.removeExtension(name); 56 | } 57 | 58 | @Override 59 | public String getName() { 60 | return _name; 61 | } 62 | 63 | @Override 64 | public void setName(final String _name) { 65 | this._name = _name; 66 | } 67 | 68 | @Override 69 | public License name(final String _name) { 70 | setName(_name); 71 | return this; 72 | } 73 | 74 | @Override 75 | public String getUrl() { 76 | return _url; 77 | } 78 | 79 | @Override 80 | public void setUrl(final String _url) { 81 | this._url = _url; 82 | } 83 | 84 | @Override 85 | public License url(final String _url) { 86 | setUrl(_url); 87 | return this; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ServerVariablesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.servers.ServerVariable; 27 | import org.eclipse.microprofile.openapi.models.servers.ServerVariables; 28 | 29 | @Vetoed 30 | public class ServerVariablesImpl extends APIMap implements ServerVariables { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | @Override 35 | @JsonbTransient 36 | public Map getExtensions() { 37 | return _extensible.getExtensions(); 38 | } 39 | 40 | @Override 41 | public void setExtensions(final Map extensions) { 42 | _extensible.setExtensions(extensions); 43 | } 44 | 45 | @Override 46 | public ServerVariables addExtension(final String name, final Object value) { 47 | _extensible.addExtension(name, value); 48 | return this; 49 | } 50 | 51 | @Override 52 | public void removeExtension(final String s) { 53 | _extensible.removeExtension(s); 54 | } 55 | 56 | @Override 57 | public ServerVariables addServerVariable(final String name, final ServerVariable item) { 58 | if (item != null) { 59 | this.put(name, item); 60 | } 61 | return this; 62 | } 63 | 64 | @Override 65 | public void removeServerVariable(final String s) { 66 | remove(s); 67 | } 68 | 69 | @Override 70 | public Map getServerVariables() { 71 | return new LinkedHashMap<>(this); 72 | } 73 | 74 | @Override 75 | public void setServerVariables(final Map map) { 76 | clear(); 77 | putAll(map); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/test/ArquillianSetup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.test; 18 | 19 | import static java.lang.String.format; 20 | 21 | import java.lang.reflect.Field; 22 | 23 | import org.apache.meecrowave.Meecrowave; 24 | import org.apache.meecrowave.arquillian.MeecrowaveContainer; 25 | import org.jboss.arquillian.container.spi.event.container.AfterStart; 26 | import org.jboss.arquillian.container.test.impl.client.protocol.local.LocalProtocol; 27 | import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentPackager; 28 | import org.jboss.arquillian.container.test.spi.client.protocol.Protocol; 29 | import org.jboss.arquillian.core.api.annotation.Observes; 30 | import org.jboss.arquillian.core.spi.LoadableExtension; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.spec.WebArchive; 34 | 35 | public class ArquillianSetup implements LoadableExtension { 36 | 37 | @Override 38 | public void register(final ExtensionBuilder extensionBuilder) { 39 | extensionBuilder.observer(Setup.class).override(Protocol.class, LocalProtocol.class, CdiProtocol.class); 40 | } 41 | 42 | public static class Setup { 43 | 44 | public void setTestUrl(@Observes final AfterStart afterStart) throws Exception { 45 | final Field container = MeecrowaveContainer.class.getDeclaredField("container"); 46 | container.setAccessible(true); 47 | final int port = Meecrowave.class.cast(container.get(afterStart.getDeployableContainer())).getConfiguration() 48 | .getHttpPort(); 49 | System.setProperty("test.url", format("http://localhost:%d", port)); 50 | } 51 | } 52 | 53 | public static class CdiProtocol extends LocalProtocol { 54 | 55 | @Override 56 | public DeploymentPackager getPackager() { 57 | return (deployment, collection) -> ShrinkWrap.create(WebArchive.class, "ROOT.war") 58 | .merge(deployment.getApplicationArchive()).addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/test/YamlAnswerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.test; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.net.URL; 23 | 24 | import javax.ws.rs.client.Client; 25 | import javax.ws.rs.client.ClientBuilder; 26 | 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.test.api.ArquillianResource; 29 | import org.jboss.arquillian.testng.Arquillian; 30 | import org.jboss.shrinkwrap.api.Archive; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.spec.WebArchive; 34 | import org.testng.annotations.Test; 35 | 36 | public class YamlAnswerTest extends Arquillian { 37 | @Deployment(testable = false) 38 | public static Archive war() { 39 | return ShrinkWrap.create(WebArchive.class, YamlAnswerTest.class.getSimpleName() + ".war") 40 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 41 | } 42 | 43 | @ArquillianResource 44 | private URL base; 45 | 46 | @Test 47 | public void getWildcard() { 48 | assertEquals("---\nopenapi: \"3.0.1\"\n", api("*/*")); 49 | } 50 | 51 | @Test 52 | public void getMissing() { // some MP server will match json even if default is set to yaml cause */*+json usage 53 | assertTrue(api("foo/bar").contains("\"3.0.1\"")); 54 | } 55 | 56 | @Test 57 | public void getTextHtml() { 58 | assertTrue(api("text/html").contains("\"3.0.1\"")); 59 | } 60 | 61 | @Test 62 | public void getYaml() { 63 | assertEquals("---\nopenapi: \"3.0.1\"\n", api("text/vnd.yaml")); 64 | } 65 | 66 | @Test 67 | public void getJson() { 68 | assertEquals("{\"openapi\":\"3.0.1\"}", api("application/json")); 69 | } 70 | 71 | private String api(final String type) { 72 | final Client client = ClientBuilder.newClient(); 73 | try { 74 | return client.target(base.toExternalForm()) 75 | .path("openapi") 76 | .request(type) 77 | .get(String.class); 78 | } finally { 79 | client.close(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/spi/NamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor.spi; 18 | 19 | import org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedMethodElement; 20 | 21 | public interface NamingStrategy { 22 | 23 | String name(Context ctx); 24 | 25 | class Context { 26 | private final AnnotatedMethodElement method; 27 | private final String httpVerb; 28 | private final String path; 29 | 30 | // @Internal 31 | public Context(final AnnotatedMethodElement method, final String httpVerb, final String path) { 32 | this.method = method; 33 | this.httpVerb = httpVerb; 34 | this.path = path; 35 | } 36 | 37 | public AnnotatedMethodElement getMethod() { 38 | return method; 39 | } 40 | 41 | public String getHttpVerb() { 42 | return httpVerb; 43 | } 44 | 45 | public String getPath() { 46 | return path; 47 | } 48 | } 49 | 50 | class Default implements NamingStrategy { 51 | @Override 52 | public String name(final Context ctx) { 53 | return ctx.method.getName(); 54 | } 55 | } 56 | 57 | class SimpleQualified implements NamingStrategy { 58 | @Override 59 | public String name(final Context ctx) { 60 | return ctx.method.getDeclaringClass().getSimpleName() + '.' + ctx.method.getName(); 61 | } 62 | } 63 | 64 | class SimpleQualifiedCamelCase implements NamingStrategy { 65 | @Override 66 | public String name(final Context ctx) { 67 | final String method = ctx.method.getName(); 68 | return ctx.method.getDeclaringClass().getSimpleName() + Character.toUpperCase(method.charAt(0)) + method.substring(1); 69 | } 70 | } 71 | 72 | class Qualified implements NamingStrategy { 73 | @Override 74 | public String name(final Context ctx) { 75 | return ctx.method.getDeclaringClass().getName() + '.' + ctx.method.getName(); 76 | } 77 | } 78 | 79 | class Http implements NamingStrategy { 80 | @Override 81 | public String name(final Context ctx) { 82 | return ctx.httpVerb + ':' + ctx.path; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/loader/DefaultLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.loader; 18 | 19 | import static java.util.Optional.ofNullable; 20 | 21 | import java.io.InputStream; 22 | import java.util.Objects; 23 | import java.util.stream.Stream; 24 | 25 | import javax.enterprise.context.ApplicationScoped; 26 | import javax.inject.Inject; 27 | import javax.json.bind.Jsonb; 28 | import javax.json.bind.JsonbBuilder; 29 | import javax.json.bind.JsonbConfig; 30 | import javax.servlet.ServletContext; 31 | 32 | import org.apache.geronimo.microprofile.openapi.impl.model.OpenAPIImpl; 33 | import org.eclipse.microprofile.openapi.models.OpenAPI; 34 | 35 | @ApplicationScoped 36 | public class DefaultLoader { 37 | @Inject 38 | private ServletContext context; 39 | 40 | public OpenAPI loadDefaultApi() { 41 | final ClassLoader loader = Thread.currentThread().getContextClassLoader(); 42 | return Stream.of("", "/").map(prefix -> prefix + "META-INF/openapi.json") 43 | .map(it -> ofNullable(loader.getResourceAsStream(it)).orElseGet(() -> context.getResourceAsStream(it))) 44 | .filter(Objects::nonNull).findFirst().map(r -> { 45 | try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig() 46 | .setProperty("johnzon.interfaceImplementationMapping", ApiBindings.get())); 47 | final InputStream stream = r) { 48 | return jsonb.fromJson(stream, OpenAPIImpl.class); 49 | } catch (final Exception e) { 50 | throw new IllegalStateException(e); 51 | } 52 | }).map(OpenAPI.class::cast) 53 | .orElseGet(() -> Stream.of("", "/").map(prefix -> prefix + "META-INF/openapi.") 54 | .flatMap(p -> Stream.of(p + "yaml", p + "yml")) 55 | .map(it -> ofNullable(loader.getResourceAsStream(it)).orElseGet(() -> context.getResourceAsStream(it))) 56 | .filter(Objects::nonNull).findFirst().map(this::loadFromYaml).orElseGet(OpenAPIImpl::new)); 57 | } 58 | 59 | private OpenAPI loadFromYaml(final InputStream inputStream) { 60 | return org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml.loadAPI(inputStream); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/jaxrs/JacksonOpenAPIYamlBodyWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.jaxrs; 18 | 19 | import static javax.ws.rs.RuntimeType.SERVER; 20 | 21 | import java.io.IOException; 22 | import java.io.OutputStream; 23 | import java.lang.annotation.Annotation; 24 | import java.lang.reflect.Type; 25 | import java.util.concurrent.atomic.AtomicReference; 26 | 27 | import javax.enterprise.context.Dependent; 28 | import javax.enterprise.inject.Vetoed; 29 | import javax.ws.rs.ConstrainedTo; 30 | import javax.ws.rs.Produces; 31 | import javax.ws.rs.WebApplicationException; 32 | import javax.ws.rs.core.MediaType; 33 | import javax.ws.rs.core.MultivaluedMap; 34 | import javax.ws.rs.ext.Provider; 35 | 36 | import org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml; 37 | 38 | @Provider 39 | @Dependent 40 | @ConstrainedTo(SERVER) 41 | @Produces({ 42 | "text/vnd.yaml", "text/yaml", "text/x-yaml", 43 | "application/vnd.yaml", "application/yaml", "application/x-yaml"}) 44 | public class JacksonOpenAPIYamlBodyWriter extends BaseOpenAPIYamlBodyWriter { 45 | @Override 46 | public void writeTo(final T entity, final Class type, final Type genericType, 47 | final Annotation[] annotations, final MediaType mediaType, 48 | final MultivaluedMap httpHeaders, final OutputStream entityStream) 49 | throws IOException, WebApplicationException { 50 | Mapper.get().writeValue(entityStream, entity); 51 | } 52 | 53 | @Vetoed 54 | private static class Mapper { 55 | private static final AtomicReference REF = new AtomicReference<>(); 56 | 57 | private Mapper() { 58 | // no-op 59 | } 60 | 61 | public static com.fasterxml.jackson.databind.ObjectMapper get() { 62 | // for now we only support jackson, ok while this is actually only tck code ;) 63 | com.fasterxml.jackson.databind.ObjectMapper mapper = REF.get(); 64 | if (mapper == null) { 65 | mapper = Yaml.getObjectMapper(); 66 | if (!REF.compareAndSet(null, mapper)) { 67 | mapper = REF.get(); 68 | } 69 | } 70 | return mapper; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/CallbackImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.PathItem; 27 | import org.eclipse.microprofile.openapi.models.callbacks.Callback; 28 | 29 | @Vetoed 30 | public class CallbackImpl extends APIMap implements Callback { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | private String _ref; 35 | 36 | @Override 37 | @JsonbTransient 38 | public Map getExtensions() { 39 | return _extensible.getExtensions(); 40 | } 41 | 42 | @Override 43 | public void setExtensions(final Map extensions) { 44 | _extensible.setExtensions(extensions); 45 | } 46 | 47 | @Override 48 | public Callback addExtension(final String name, final Object value) { 49 | _extensible.addExtension(name, value); 50 | return this; 51 | } 52 | 53 | @Override 54 | public void removeExtension(final String name) { 55 | _extensible.removeExtension(name); 56 | } 57 | 58 | @Override 59 | public Callback addPathItem(final String name, final PathItem item) { 60 | if (item != null) { 61 | super.put(name, item); 62 | } 63 | return this; 64 | } 65 | 66 | @Override 67 | public void removePathItem(final String name) { 68 | remove(name); 69 | } 70 | 71 | @Override 72 | public Map getPathItems() { 73 | return new LinkedHashMap<>(this); 74 | } 75 | 76 | @Override 77 | public void setPathItems(final Map items) { 78 | clear(); 79 | putAll(items); 80 | } 81 | 82 | @Override 83 | public String getRef() { 84 | return _ref; 85 | } 86 | 87 | @Override 88 | public void setRef(final String _ref) { 89 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/callbacks/" + _ref); 90 | } 91 | 92 | @Override 93 | public Callback ref(final String _ref) { 94 | setRef(_ref); 95 | return this; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ContactImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.info.Contact; 26 | 27 | @Vetoed 28 | public class ContactImpl implements Contact { 29 | 30 | private Extensible _extensible = new ExtensibleImpl(); 31 | 32 | private String _email; 33 | 34 | private String _name; 35 | 36 | private String _url; 37 | 38 | @Override 39 | @JsonbTransient 40 | public Map getExtensions() { 41 | return _extensible.getExtensions(); 42 | } 43 | 44 | @Override 45 | public void setExtensions(final Map extensions) { 46 | _extensible.setExtensions(extensions); 47 | } 48 | 49 | @Override 50 | public Contact addExtension(final String name, final Object value) { 51 | _extensible.addExtension(name, value); 52 | return this; 53 | } 54 | 55 | @Override 56 | public void removeExtension(final String name) { 57 | _extensible.removeExtension(name); 58 | } 59 | 60 | @Override 61 | public String getEmail() { 62 | return _email; 63 | } 64 | 65 | @Override 66 | public void setEmail(final String _email) { 67 | this._email = _email; 68 | } 69 | 70 | @Override 71 | public Contact email(final String _email) { 72 | setEmail(_email); 73 | return this; 74 | } 75 | 76 | @Override 77 | public String getName() { 78 | return _name; 79 | } 80 | 81 | @Override 82 | public void setName(final String _name) { 83 | this._name = _name; 84 | } 85 | 86 | @Override 87 | public Contact name(final String _name) { 88 | setName(_name); 89 | return this; 90 | } 91 | 92 | @Override 93 | public String getUrl() { 94 | return _url; 95 | } 96 | 97 | @Override 98 | public void setUrl(final String _url) { 99 | this._url = _url; 100 | } 101 | 102 | @Override 103 | public Contact url(final String _url) { 104 | setUrl(_url); 105 | return this; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/reflect/ClassElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor.reflect; 18 | 19 | import org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedTypeElement; 20 | 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Type; 23 | import java.util.Collection; 24 | import java.util.LinkedList; 25 | import java.util.stream.Stream; 26 | 27 | import static java.util.Arrays.asList; 28 | import static java.util.Optional.ofNullable; 29 | import static java.util.stream.Collectors.toList; 30 | 31 | public class ClassElement implements AnnotatedTypeElement { 32 | private final Class delegate; 33 | private Annotation[] annotations; 34 | 35 | public ClassElement(final Class delegate) { 36 | this.delegate = delegate; 37 | } 38 | 39 | @Override 40 | public T getAnnotation(final Class annotationClass) { 41 | return ofNullable(delegate.getAnnotation(annotationClass)) 42 | .orElseGet(() -> findInInterfaces(annotationClass)); 43 | } 44 | 45 | @Override 46 | public Annotation[] getAnnotations() { 47 | return annotations == null ? annotations = gatherAnnotations() : annotations; 48 | } 49 | 50 | @Override 51 | public Annotation[] getDeclaredAnnotations() { 52 | return getAnnotations(); 53 | } 54 | 55 | @Override 56 | public Type getType() { 57 | return delegate; 58 | } 59 | 60 | private Annotation[] gatherAnnotations() { 61 | final Collection annotations = new LinkedList<>(asList(delegate.getAnnotations())); 62 | annotations.addAll(findInterfaces(delegate) 63 | .flatMap(i -> Stream.of(i.getAnnotations()).filter(it -> !delegate.isAnnotationPresent(it.annotationType()))) 64 | .distinct() 65 | .collect(toList())); 66 | return annotations.toArray(new Annotation[0]); 67 | } 68 | 69 | private T findInInterfaces(final Class annotationClass) { 70 | return findInterfaces(delegate) 71 | .filter(it -> it.isAnnotationPresent(annotationClass)) 72 | .findFirst() 73 | .map(it -> it.getAnnotation(annotationClass)) 74 | .orElse(null); 75 | } 76 | 77 | private Stream> findInterfaces(final Class delegate) { 78 | return Stream.of(delegate.getInterfaces()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/serialization/SerializationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.serialization; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import javax.json.bind.Jsonb; 22 | import javax.json.bind.JsonbBuilder; 23 | import javax.json.bind.JsonbConfig; 24 | import javax.json.bind.config.PropertyOrderStrategy; 25 | 26 | import org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml; 27 | import org.apache.geronimo.microprofile.openapi.impl.model.APIResponseImpl; 28 | import org.apache.geronimo.microprofile.openapi.impl.model.APIResponsesImpl; 29 | import org.apache.geronimo.microprofile.openapi.impl.model.CallbackImpl; 30 | import org.apache.geronimo.microprofile.openapi.impl.model.InfoImpl; 31 | import org.apache.geronimo.microprofile.openapi.impl.model.OpenAPIImpl; 32 | import org.apache.geronimo.microprofile.openapi.impl.model.OperationImpl; 33 | import org.apache.geronimo.microprofile.openapi.impl.model.PathItemImpl; 34 | import org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl; 35 | import org.eclipse.microprofile.openapi.models.OpenAPI; 36 | import org.eclipse.microprofile.openapi.models.PathItem; 37 | import org.eclipse.microprofile.openapi.models.responses.APIResponses; 38 | import org.testng.annotations.Test; 39 | 40 | public class SerializationTest { 41 | @Test 42 | public void defaultResponse() throws Exception { 43 | final APIResponses responses = new APIResponsesImpl() 44 | .defaultValue(new APIResponseImpl().description("test")) 45 | .addAPIResponse("200", new APIResponseImpl().description("ok")); 46 | try (final Jsonb jsonb = JsonbBuilder.create()) { 47 | assertEquals("{\"default\":{\"description\":\"test\"},\"200\":{\"description\":\"ok\"}}", jsonb.toJson(responses)); 48 | } 49 | assertEquals("---\ndefault:\n description: \"test\"\n\"200\":\n description: \"ok\"\n", Yaml.getObjectMapper().writeValueAsString(responses)); 50 | } 51 | 52 | @Test 53 | public void serialize() throws Exception { 54 | final PathItem item = new PathItemImpl(); 55 | item.setGET(new OperationImpl().addCallback("onData", new CallbackImpl() 56 | .addPathItem("{$request.query.callbackUrl}/data", new PathItemImpl()))); 57 | 58 | final OpenAPI api = new OpenAPIImpl() 59 | .info(new InfoImpl().version("3.0.0")) 60 | .paths(new PathsImpl().addPathItem("/foo", item)); 61 | 62 | // identify some jsonb issues with serializers early (exception) 63 | try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig() 64 | .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL))) { 65 | jsonb.toJson(api); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ExternalDocumentationImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | import java.util.Objects; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.ExternalDocumentation; 27 | 28 | @Vetoed 29 | public class ExternalDocumentationImpl implements ExternalDocumentation { 30 | 31 | private Extensible _extensible = new ExtensibleImpl(); 32 | 33 | private String _description; 34 | 35 | private String _url; 36 | 37 | @Override 38 | @JsonbTransient 39 | public Map getExtensions() { 40 | return _extensible.getExtensions(); 41 | } 42 | 43 | @Override 44 | public void setExtensions(final Map extensions) { 45 | _extensible.setExtensions(extensions); 46 | } 47 | 48 | @Override 49 | public ExternalDocumentation addExtension(final String name, final Object value) { 50 | _extensible.addExtension(name, value); 51 | return this; 52 | } 53 | 54 | @Override 55 | public void removeExtension(final String name) { 56 | _extensible.removeExtension(name); 57 | } 58 | 59 | @Override 60 | public String getDescription() { 61 | return _description; 62 | } 63 | 64 | @Override 65 | public void setDescription(final String _description) { 66 | this._description = _description; 67 | } 68 | 69 | @Override 70 | public ExternalDocumentation description(final String _description) { 71 | setDescription(_description); 72 | return this; 73 | } 74 | 75 | @Override 76 | public String getUrl() { 77 | return _url; 78 | } 79 | 80 | @Override 81 | public void setUrl(final String _url) { 82 | this._url = _url; 83 | } 84 | 85 | @Override 86 | public ExternalDocumentation url(final String _url) { 87 | setUrl(_url); 88 | return this; 89 | } 90 | 91 | @Override 92 | public boolean equals(final Object o) { 93 | if (this == o) { 94 | return true; 95 | } 96 | if (o == null || getClass() != o.getClass()) { 97 | return false; 98 | } 99 | final ExternalDocumentationImpl that = ExternalDocumentationImpl.class.cast(o); 100 | return Objects.equals(_extensible, that._extensible) && Objects.equals(_description, 101 | that._description) && Objects.equals(_url, that._url); 102 | } 103 | 104 | @Override 105 | public int hashCode() { 106 | return Objects.hash(_extensible, _description, _url); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/APIResponsesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.responses.APIResponse; 27 | import org.eclipse.microprofile.openapi.models.responses.APIResponses; 28 | 29 | @Vetoed 30 | public class APIResponsesImpl extends APIMap implements APIResponses { 31 | private Extensible _extensible = new ExtensibleImpl<>(); 32 | 33 | public APIResponses addAPIResponse(final String name, final APIResponse item) { 34 | return addApiResponse(name, item); 35 | } 36 | 37 | @Override 38 | public void removeAPIResponse(final String name) { 39 | remove(name); 40 | } 41 | 42 | @Override 43 | public Map getAPIResponses() { 44 | return new LinkedHashMap<>(this); 45 | } 46 | 47 | @Override 48 | public void setAPIResponses(final Map items) { 49 | clear(); 50 | putAll(items); 51 | } 52 | 53 | @Override 54 | public APIResponses addApiResponse(final String name, final APIResponse item) { 55 | if (item != null) { 56 | super.put(name, item); 57 | } 58 | return this; 59 | } 60 | 61 | @Override 62 | @JsonbTransient 63 | public APIResponse getDefault() { 64 | return get("default"); 65 | } 66 | 67 | @Override 68 | public APIResponse getDefaultValue() { 69 | return getDefault(); 70 | } 71 | 72 | @Override 73 | public void setDefaultValue(final APIResponse _defaultValue) { 74 | if (_defaultValue == null) { 75 | removeAPIResponse(APIResponses.DEFAULT); 76 | } else { 77 | addApiResponse(APIResponses.DEFAULT, _defaultValue); 78 | } 79 | } 80 | 81 | @Override 82 | public APIResponses defaultValue(final APIResponse _defaultValue) { 83 | setDefaultValue(_defaultValue); 84 | return this; 85 | } 86 | 87 | @Override 88 | @JsonbTransient 89 | public Map getExtensions() { 90 | return _extensible.getExtensions(); 91 | } 92 | 93 | @Override 94 | public APIResponses addExtension(final String name, final Object value) { 95 | _extensible.addExtension(name, value); 96 | return this; 97 | } 98 | 99 | @Override 100 | public void removeExtension(final String name) { 101 | _extensible.removeExtension(name); 102 | } 103 | 104 | @Override 105 | public void setExtensions(final Map extensions) { 106 | _extensible.setExtensions(extensions); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/OAuthFlowImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.security.OAuthFlow; 26 | import org.eclipse.microprofile.openapi.models.security.Scopes; 27 | 28 | @Vetoed 29 | public class OAuthFlowImpl implements OAuthFlow { 30 | 31 | private Extensible _extensible = new ExtensibleImpl(); 32 | 33 | private String _authorizationUrl; 34 | 35 | private String _refreshUrl; 36 | 37 | private Scopes _scopes; 38 | 39 | private String _tokenUrl; 40 | 41 | @Override 42 | @JsonbTransient 43 | public Map getExtensions() { 44 | return _extensible.getExtensions(); 45 | } 46 | 47 | @Override 48 | public void setExtensions(final Map extensions) { 49 | _extensible.setExtensions(extensions); 50 | } 51 | 52 | @Override 53 | public OAuthFlow addExtension(final String name, final Object value) { 54 | _extensible.addExtension(name, value); 55 | return this; 56 | } 57 | 58 | @Override 59 | public void removeExtension(final String name) { 60 | _extensible.removeExtension(name); 61 | } 62 | 63 | @Override 64 | public String getAuthorizationUrl() { 65 | return _authorizationUrl; 66 | } 67 | 68 | @Override 69 | public void setAuthorizationUrl(final String _authorizationUrl) { 70 | this._authorizationUrl = _authorizationUrl; 71 | } 72 | 73 | @Override 74 | public OAuthFlow authorizationUrl(final String _authorizationUrl) { 75 | setAuthorizationUrl(_authorizationUrl); 76 | return this; 77 | } 78 | 79 | @Override 80 | public String getRefreshUrl() { 81 | return _refreshUrl; 82 | } 83 | 84 | @Override 85 | public void setRefreshUrl(final String _refreshUrl) { 86 | this._refreshUrl = _refreshUrl; 87 | } 88 | 89 | @Override 90 | public OAuthFlow refreshUrl(final String _refreshUrl) { 91 | setRefreshUrl(_refreshUrl); 92 | return this; 93 | } 94 | 95 | @Override 96 | public Scopes getScopes() { 97 | return _scopes; 98 | } 99 | 100 | @Override 101 | public void setScopes(final Scopes _scopes) { 102 | this._scopes = _scopes; 103 | } 104 | 105 | @Override 106 | public OAuthFlow scopes(final Scopes _scopes) { 107 | setScopes(_scopes); 108 | return this; 109 | } 110 | 111 | @Override 112 | public String getTokenUrl() { 113 | return _tokenUrl; 114 | } 115 | 116 | @Override 117 | public void setTokenUrl(final String _tokenUrl) { 118 | this._tokenUrl = _tokenUrl; 119 | } 120 | 121 | @Override 122 | public OAuthFlow tokenUrl(final String _tokenUrl) { 123 | setTokenUrl(_tokenUrl); 124 | return this; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ServerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbProperty; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.servers.Server; 27 | import org.eclipse.microprofile.openapi.models.servers.ServerVariable; 28 | import org.eclipse.microprofile.openapi.models.servers.ServerVariables; 29 | 30 | @Vetoed 31 | public class ServerImpl implements Server { 32 | 33 | private Extensible _extensible = new ExtensibleImpl(); 34 | 35 | private String _description; 36 | 37 | private String _url; 38 | 39 | private ServerVariables _variables; 40 | 41 | @Override 42 | @JsonbTransient 43 | public Map getExtensions() { 44 | return _extensible.getExtensions(); 45 | } 46 | 47 | @Override 48 | public void setExtensions(final Map extensions) { 49 | _extensible.setExtensions(extensions); 50 | } 51 | 52 | @Override 53 | public Server addExtension(final String name, final Object value) { 54 | _extensible.addExtension(name, value); 55 | return this; 56 | } 57 | 58 | @Override 59 | public void removeExtension(final String s) { 60 | _extensible.removeExtension(s); 61 | } 62 | 63 | @Override 64 | public String getDescription() { 65 | return _description; 66 | } 67 | 68 | @Override 69 | public void setDescription(final String _description) { 70 | this._description = _description; 71 | } 72 | 73 | @Override 74 | public Server description(final String _description) { 75 | setDescription(_description); 76 | return this; 77 | } 78 | 79 | @Override 80 | public String getUrl() { 81 | return _url; 82 | } 83 | 84 | @Override 85 | public void setUrl(final String _url) { 86 | this._url = _url; 87 | } 88 | 89 | @Override 90 | public Server url(final String _url) { 91 | setUrl(_url); 92 | return this; 93 | } 94 | 95 | @Override 96 | @JsonbProperty("variables") 97 | public ServerVariables getVariables() { 98 | return _variables; 99 | } 100 | 101 | @Override 102 | @JsonbProperty("variables") 103 | public void setVariables(final ServerVariables _variables) { 104 | this._variables = _variables; 105 | } 106 | 107 | @Override 108 | @JsonbTransient 109 | public void setVariables(final Map map) { 110 | if (map != null) { 111 | this._variables = new ServerVariablesImpl(); 112 | map.forEach((k, v) -> this._variables.addServerVariable(k, v)); 113 | } else { 114 | this._variables = null; 115 | } 116 | } 117 | 118 | @Override 119 | public Server variables(final ServerVariables _variables) { 120 | setVariables(_variables); 121 | return this; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/RequestBodyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbProperty; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.media.Content; 27 | import org.eclipse.microprofile.openapi.models.parameters.RequestBody; 28 | 29 | @Vetoed 30 | public class RequestBodyImpl implements RequestBody { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | private Content _content; 35 | 36 | private String _description; 37 | 38 | private String _ref; 39 | 40 | private Boolean _required; 41 | 42 | @Override 43 | @JsonbTransient 44 | public Map getExtensions() { 45 | return _extensible.getExtensions(); 46 | } 47 | 48 | @Override 49 | public void setExtensions(final Map extensions) { 50 | _extensible.setExtensions(extensions); 51 | } 52 | 53 | @Override 54 | public RequestBody addExtension(final String name, final Object value) { 55 | _extensible.addExtension(name, value); 56 | return this; 57 | } 58 | 59 | @Override 60 | public void removeExtension(final String name) { 61 | _extensible.removeExtension(name); 62 | } 63 | 64 | @Override 65 | public Content getContent() { 66 | return _content; 67 | } 68 | 69 | @Override 70 | public void setContent(final Content _content) { 71 | this._content = _content; 72 | } 73 | 74 | @Override 75 | public RequestBody content(final Content _content) { 76 | setContent(_content); 77 | return this; 78 | } 79 | 80 | @Override 81 | public String getDescription() { 82 | return _description; 83 | } 84 | 85 | @Override 86 | public void setDescription(final String _description) { 87 | this._description = _description; 88 | } 89 | 90 | @Override 91 | public RequestBody description(final String _description) { 92 | setDescription(_description); 93 | return this; 94 | } 95 | 96 | @Override 97 | @JsonbProperty("$ref") 98 | public String getRef() { 99 | return _ref; 100 | } 101 | 102 | @Override 103 | @JsonbProperty("$ref") 104 | public void setRef(final String _ref) { 105 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/requestBodies/" + _ref); 106 | } 107 | 108 | @Override 109 | public RequestBody ref(final String _ref) { 110 | setRef(_ref); 111 | return this; 112 | } 113 | 114 | @Override 115 | public Boolean getRequired() { 116 | return _required; 117 | } 118 | 119 | @Override 120 | public void setRequired(final Boolean _required) { 121 | this._required = _required; 122 | } 123 | 124 | @Override 125 | public RequestBody required(final Boolean _required) { 126 | setRequired(_required); 127 | return this; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/OAuthFlowsImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.security.OAuthFlow; 26 | import org.eclipse.microprofile.openapi.models.security.OAuthFlows; 27 | 28 | @Vetoed 29 | public class OAuthFlowsImpl implements OAuthFlows { 30 | 31 | private Extensible _extensible = new ExtensibleImpl(); 32 | 33 | private OAuthFlow _authorizationCode; 34 | 35 | private OAuthFlow _clientCredentials; 36 | 37 | private OAuthFlow _implicit; 38 | 39 | private OAuthFlow _password; 40 | 41 | @Override 42 | @JsonbTransient 43 | public Map getExtensions() { 44 | return _extensible.getExtensions(); 45 | } 46 | 47 | @Override 48 | public void setExtensions(final Map extensions) { 49 | _extensible.setExtensions(extensions); 50 | } 51 | 52 | @Override 53 | public OAuthFlows addExtension(final String name, final Object value) { 54 | _extensible.addExtension(name, value); 55 | return this; 56 | } 57 | 58 | @Override 59 | public void removeExtension(final String name) { 60 | _extensible.removeExtension(name); 61 | } 62 | 63 | @Override 64 | public OAuthFlow getAuthorizationCode() { 65 | return _authorizationCode; 66 | } 67 | 68 | @Override 69 | public void setAuthorizationCode(final OAuthFlow _authorizationCode) { 70 | this._authorizationCode = _authorizationCode; 71 | } 72 | 73 | @Override 74 | public OAuthFlows authorizationCode(final OAuthFlow _authorizationCode) { 75 | setAuthorizationCode(_authorizationCode); 76 | return this; 77 | } 78 | 79 | @Override 80 | public OAuthFlow getClientCredentials() { 81 | return _clientCredentials; 82 | } 83 | 84 | @Override 85 | public void setClientCredentials(final OAuthFlow _clientCredentials) { 86 | this._clientCredentials = _clientCredentials; 87 | } 88 | 89 | @Override 90 | public OAuthFlows clientCredentials(final OAuthFlow _clientCredentials) { 91 | setClientCredentials(_clientCredentials); 92 | return this; 93 | } 94 | 95 | @Override 96 | public OAuthFlow getImplicit() { 97 | return _implicit; 98 | } 99 | 100 | @Override 101 | public void setImplicit(final OAuthFlow _implicit) { 102 | this._implicit = _implicit; 103 | } 104 | 105 | @Override 106 | public OAuthFlows implicit(final OAuthFlow _implicit) { 107 | setImplicit(_implicit); 108 | return this; 109 | } 110 | 111 | @Override 112 | public OAuthFlow getPassword() { 113 | return _password; 114 | } 115 | 116 | @Override 117 | public void setPassword(final OAuthFlow _password) { 118 | this._password = _password; 119 | } 120 | 121 | @Override 122 | public OAuthFlows password(final OAuthFlow _password) { 123 | setPassword(_password); 124 | return this; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/XMLImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.media.XML; 26 | 27 | @Vetoed 28 | public class XMLImpl implements XML { 29 | 30 | private Extensible _extensible = new ExtensibleImpl(); 31 | 32 | private Boolean _attribute; 33 | 34 | private String _name; 35 | 36 | private String _namespace; 37 | 38 | private String _prefix; 39 | 40 | private Boolean _wrapped; 41 | 42 | @Override 43 | @JsonbTransient 44 | public Map getExtensions() { 45 | return _extensible.getExtensions(); 46 | } 47 | 48 | @Override 49 | public void setExtensions(final Map extensions) { 50 | _extensible.setExtensions(extensions); 51 | } 52 | 53 | @Override 54 | public XML addExtension(final String name, final Object value) { 55 | _extensible.addExtension(name, value); 56 | return this; 57 | } 58 | 59 | @Override 60 | public void removeExtension(final String name) { 61 | _extensible.removeExtension(name); 62 | } 63 | 64 | @Override 65 | public Boolean getAttribute() { 66 | return _attribute; 67 | } 68 | 69 | @Override 70 | public void setAttribute(final Boolean _attribute) { 71 | this._attribute = _attribute; 72 | } 73 | 74 | @Override 75 | public XML attribute(final Boolean _attribute) { 76 | setAttribute(_attribute); 77 | return this; 78 | } 79 | 80 | @Override 81 | public String getName() { 82 | return _name; 83 | } 84 | 85 | @Override 86 | public void setName(final String _name) { 87 | this._name = _name; 88 | } 89 | 90 | @Override 91 | public XML name(final String _name) { 92 | setName(_name); 93 | return this; 94 | } 95 | 96 | @Override 97 | public String getNamespace() { 98 | return _namespace; 99 | } 100 | 101 | @Override 102 | public void setNamespace(final String _namespace) { 103 | this._namespace = _namespace; 104 | } 105 | 106 | @Override 107 | public XML namespace(final String _namespace) { 108 | setNamespace(_namespace); 109 | return this; 110 | } 111 | 112 | @Override 113 | public String getPrefix() { 114 | return _prefix; 115 | } 116 | 117 | @Override 118 | public void setPrefix(final String _prefix) { 119 | this._prefix = _prefix; 120 | } 121 | 122 | @Override 123 | public XML prefix(final String _prefix) { 124 | setPrefix(_prefix); 125 | return this; 126 | } 127 | 128 | @Override 129 | public Boolean getWrapped() { 130 | return _wrapped; 131 | } 132 | 133 | @Override 134 | public void setWrapped(final Boolean _wrapped) { 135 | this._wrapped = _wrapped; 136 | } 137 | 138 | @Override 139 | public XML wrapped(final Boolean _wrapped) { 140 | setWrapped(_wrapped); 141 | return this; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ServerVariableImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import javax.enterprise.inject.Vetoed; 24 | import javax.json.bind.annotation.JsonbProperty; 25 | import javax.json.bind.annotation.JsonbTransient; 26 | 27 | import org.eclipse.microprofile.openapi.models.Extensible; 28 | import org.eclipse.microprofile.openapi.models.servers.ServerVariable; 29 | 30 | @Vetoed 31 | public class ServerVariableImpl implements ServerVariable { 32 | 33 | private Extensible _extensible = new ExtensibleImpl(); 34 | 35 | private String _defaultValue; 36 | 37 | private String _description; 38 | 39 | private List _enumeration; 40 | 41 | @Override 42 | @JsonbTransient 43 | public Map getExtensions() { 44 | return _extensible.getExtensions(); 45 | } 46 | 47 | @Override 48 | public void setExtensions(final Map extensions) { 49 | _extensible.setExtensions(extensions); 50 | } 51 | 52 | @Override 53 | public ServerVariable addExtension(final String name, final Object value) { 54 | _extensible.addExtension(name, value); 55 | return this; 56 | } 57 | 58 | @Override 59 | public void removeExtension(final String name) { 60 | _extensible.removeExtension(name); 61 | } 62 | 63 | @Override 64 | public void removeEnumeration(final String enumeration) { 65 | _enumeration.remove(enumeration); 66 | } 67 | 68 | @Override 69 | @JsonbProperty("default") 70 | public String getDefaultValue() { 71 | return _defaultValue; 72 | } 73 | 74 | @Override 75 | @JsonbProperty("default") 76 | public void setDefaultValue(final String _defaultValue) { 77 | this._defaultValue = _defaultValue; 78 | } 79 | 80 | @Override 81 | public ServerVariable defaultValue(final String _defaultValue) { 82 | setDefaultValue(_defaultValue); 83 | return this; 84 | } 85 | 86 | @Override 87 | public String getDescription() { 88 | return _description; 89 | } 90 | 91 | @Override 92 | public void setDescription(final String _description) { 93 | this._description = _description; 94 | } 95 | 96 | @Override 97 | public ServerVariable description(final String _description) { 98 | setDescription(_description); 99 | return this; 100 | } 101 | 102 | @Override 103 | @JsonbProperty("enum") 104 | public List getEnumeration() { 105 | return _enumeration; 106 | } 107 | 108 | @Override 109 | @JsonbProperty("enum") 110 | public void setEnumeration(final List _enumeration) { 111 | this._enumeration = _enumeration; 112 | } 113 | 114 | @Override 115 | public ServerVariable enumeration(final List _enumeration) { 116 | setEnumeration(_enumeration); 117 | return this; 118 | } 119 | 120 | @Override 121 | public ServerVariable addEnumeration(final String enumeration) { 122 | (_enumeration = _enumeration == null ? new ArrayList<>() : _enumeration).add(enumeration); 123 | return this; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/TagImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | import java.util.Objects; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.ExternalDocumentation; 27 | import org.eclipse.microprofile.openapi.models.tags.Tag; 28 | 29 | @Vetoed 30 | public class TagImpl implements Tag { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | private String _description; 35 | 36 | private ExternalDocumentation _externalDocs; 37 | 38 | private String _name; 39 | 40 | @Override 41 | @JsonbTransient 42 | public Map getExtensions() { 43 | return _extensible.getExtensions(); 44 | } 45 | 46 | @Override 47 | public void setExtensions(final Map extensions) { 48 | _extensible.setExtensions(extensions); 49 | } 50 | 51 | @Override 52 | public Tag addExtension(final String name, final Object value) { 53 | _extensible.addExtension(name, value); 54 | return this; 55 | } 56 | 57 | @Override 58 | public void removeExtension(final String name) { 59 | _extensible.removeExtension(name); 60 | } 61 | 62 | @Override 63 | public String getDescription() { 64 | return _description; 65 | } 66 | 67 | @Override 68 | public void setDescription(final String _description) { 69 | this._description = _description; 70 | } 71 | 72 | @Override 73 | public Tag description(final String _description) { 74 | setDescription(_description); 75 | return this; 76 | } 77 | 78 | @Override 79 | public ExternalDocumentation getExternalDocs() { 80 | return _externalDocs; 81 | } 82 | 83 | @Override 84 | public void setExternalDocs(final ExternalDocumentation _externalDocs) { 85 | this._externalDocs = _externalDocs; 86 | } 87 | 88 | @Override 89 | public Tag externalDocs(final ExternalDocumentation _externalDocs) { 90 | setExternalDocs(_externalDocs); 91 | return this; 92 | } 93 | 94 | @Override 95 | public String getName() { 96 | return _name; 97 | } 98 | 99 | @Override 100 | public void setName(final String _name) { 101 | this._name = _name; 102 | } 103 | 104 | @Override 105 | public Tag name(final String _name) { 106 | setName(_name); 107 | return this; 108 | } 109 | 110 | @Override 111 | public boolean equals(final Object o) { 112 | if (this == o) { 113 | return true; 114 | } 115 | if (o == null || getClass() != o.getClass()) { 116 | return false; 117 | } 118 | final TagImpl tag = TagImpl.class.cast(o); 119 | return Objects.equals(_extensible, tag._extensible) && Objects.equals(_description, 120 | tag._description) && Objects.equals(_externalDocs, tag._externalDocs) && Objects.equals(_name, 121 | tag._name); 122 | } 123 | 124 | @Override 125 | public int hashCode() { 126 | return Objects.hash(_extensible, _description, _externalDocs, _name); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/src/test/java/org/apache/geronimo/microprofile/openapi/mojo/OpenAPIMojoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.mojo; 18 | 19 | import static java.util.Collections.emptyList; 20 | import static java.util.Collections.singleton; 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertNotNull; 23 | 24 | import java.io.File; 25 | import java.io.FileInputStream; 26 | import java.io.InputStream; 27 | 28 | import javax.json.bind.Jsonb; 29 | import javax.json.bind.JsonbBuilder; 30 | import javax.json.bind.JsonbConfig; 31 | import javax.ws.rs.GET; 32 | import javax.ws.rs.Path; 33 | import javax.ws.rs.PathParam; 34 | import javax.ws.rs.Produces; 35 | import javax.ws.rs.core.MediaType; 36 | 37 | import org.apache.geronimo.microprofile.openapi.impl.loader.ApiBindings; 38 | import org.apache.geronimo.microprofile.openapi.impl.model.OpenAPIImpl; 39 | import org.apache.maven.project.MavenProject; 40 | import org.eclipse.microprofile.openapi.models.OpenAPI; 41 | import org.eclipse.microprofile.openapi.models.Operation; 42 | import org.eclipse.microprofile.openapi.models.media.Schema; 43 | import org.junit.Test; 44 | 45 | public class OpenAPIMojoTest { 46 | @Test 47 | public void scan() throws Exception { 48 | final OpenAPIMojo mojo = new OpenAPIMojo(); 49 | mojo.output = new File("target/OpenAPIMojoTest_scan_1.json"); 50 | mojo.classes = new File("target/test-classes"); 51 | mojo.endpointClasses = emptyList(); 52 | doExecuteAndAssert(mojo); 53 | } 54 | 55 | @Test 56 | public void run() throws Exception { 57 | final OpenAPIMojo mojo = new OpenAPIMojo(); 58 | mojo.output = new File("target/OpenAPIMojoTest_run_1.json"); 59 | mojo.endpointClasses = singleton(HelloServiceImpl1.class.getName()); 60 | doExecuteAndAssert(mojo); 61 | } 62 | 63 | private void doExecuteAndAssert(final OpenAPIMojo mojo) throws Exception { 64 | mojo.project = new MavenProject(); 65 | mojo.project.setVersion("1.2.3"); 66 | mojo.execute(); 67 | final OpenAPI openAPI = readOpenAPI(mojo.output); 68 | assertNotNull(openAPI.getInfo()); 69 | assertEquals("1.2.3", openAPI.getInfo().getVersion()); 70 | final Operation get = openAPI.getPaths().getPathItem("/sayHello/{a}").getGET(); 71 | assertNotNull(get); 72 | assertEquals(1, get.getParameters().size()); 73 | assertEquals("a", get.getParameters().iterator().next().getName()); 74 | assertEquals(Schema.SchemaType.STRING, get.getResponses().getAPIResponse("200").getContent().getMediaType("text/plain").getSchema().getType()); 75 | } 76 | 77 | private OpenAPI readOpenAPI(final File output) throws Exception { 78 | try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().setProperty("johnzon.interfaceImplementationMapping", ApiBindings.get())); 79 | final InputStream stream = new FileInputStream(output)) { 80 | return jsonb.fromJson(stream, OpenAPIImpl.class); 81 | } 82 | } 83 | 84 | @Path("/sayHello") 85 | public interface HelloService { 86 | @GET 87 | @Path("/{a}") 88 | @Produces(MediaType.TEXT_PLAIN) 89 | String hi(@PathParam("a") String a); 90 | 91 | } 92 | 93 | public static class HelloServiceImpl1 implements HelloService { 94 | 95 | public String hi(String a) { 96 | return ""; 97 | } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/ExampleImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbProperty; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | 25 | import org.eclipse.microprofile.openapi.models.Extensible; 26 | import org.eclipse.microprofile.openapi.models.examples.Example; 27 | 28 | @Vetoed 29 | public class ExampleImpl implements Example { 30 | 31 | private Extensible _extensible = new ExtensibleImpl(); 32 | 33 | private String _description; 34 | 35 | private String _externalValue; 36 | 37 | private String _ref; 38 | 39 | private String _summary; 40 | 41 | private Object _value; 42 | 43 | @Override 44 | @JsonbTransient 45 | public Map getExtensions() { 46 | return _extensible.getExtensions(); 47 | } 48 | 49 | @Override 50 | public void setExtensions(final Map extensions) { 51 | _extensible.setExtensions(extensions); 52 | } 53 | 54 | @Override 55 | public Example addExtension(final String name, final Object value) { 56 | _extensible.addExtension(name, value); 57 | return this; 58 | } 59 | 60 | @Override 61 | public void removeExtension(final String name) { 62 | _extensible.removeExtension(name); 63 | } 64 | 65 | @Override 66 | public String getDescription() { 67 | return _description; 68 | } 69 | 70 | @Override 71 | public void setDescription(final String _description) { 72 | this._description = _description; 73 | } 74 | 75 | @Override 76 | public Example description(final String _description) { 77 | setDescription(_description); 78 | return this; 79 | } 80 | 81 | @Override 82 | public String getExternalValue() { 83 | return _externalValue; 84 | } 85 | 86 | @Override 87 | public void setExternalValue(final String _externalValue) { 88 | this._externalValue = _externalValue; 89 | } 90 | 91 | @Override 92 | public Example externalValue(final String _externalValue) { 93 | setExternalValue(_externalValue); 94 | return this; 95 | } 96 | 97 | @Override 98 | @JsonbProperty("$ref") 99 | public String getRef() { 100 | return _ref; 101 | } 102 | 103 | @Override 104 | @JsonbProperty("$ref") 105 | public void setRef(final String _ref) { 106 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/examples/" + _ref); 107 | } 108 | 109 | @Override 110 | public Example ref(final String _ref) { 111 | setRef(_ref); 112 | return this; 113 | } 114 | 115 | @Override 116 | public String getSummary() { 117 | return _summary; 118 | } 119 | 120 | @Override 121 | public void setSummary(final String _summary) { 122 | this._summary = _summary; 123 | } 124 | 125 | @Override 126 | public Example summary(final String _summary) { 127 | setSummary(_summary); 128 | return this; 129 | } 130 | 131 | @Override 132 | public Object getValue() { 133 | return _value; 134 | } 135 | 136 | @Override 137 | public void setValue(final Object _value) { 138 | this._value = _value; 139 | } 140 | 141 | @Override 142 | public Example value(final Object _value) { 143 | setValue(_value); 144 | return this; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/jaxrs/OpenAPIFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.jaxrs; 18 | 19 | import static javax.ws.rs.Priorities.USER; 20 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; 21 | import static javax.ws.rs.core.MediaType.WILDCARD_TYPE; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.List; 25 | 26 | import javax.annotation.PostConstruct; 27 | import javax.annotation.Priority; 28 | import javax.enterprise.context.Dependent; 29 | import javax.inject.Inject; 30 | import javax.ws.rs.HttpMethod; 31 | import javax.ws.rs.container.ContainerRequestContext; 32 | import javax.ws.rs.container.ContainerRequestFilter; 33 | import javax.ws.rs.container.PreMatching; 34 | import javax.ws.rs.core.Application; 35 | import javax.ws.rs.core.Context; 36 | import javax.ws.rs.core.MediaType; 37 | import javax.ws.rs.core.Response; 38 | import javax.ws.rs.ext.Provider; 39 | import javax.ws.rs.ext.Providers; 40 | 41 | import org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension; 42 | import org.eclipse.microprofile.openapi.models.OpenAPI; 43 | 44 | // theorically a jaxrs endpoint to benefit from jaxrs tooling and filters - but forbidden by TCK :( 45 | // @Path("openapi") + @GET 46 | @Provider 47 | @Dependent 48 | @PreMatching 49 | @Priority(USER) 50 | public class OpenAPIFilter implements ContainerRequestFilter { 51 | 52 | private static final Annotation[] NO_ANNOTATION = new Annotation[0]; 53 | 54 | @Inject 55 | private GeronimoOpenAPIExtension extension; 56 | 57 | @Context 58 | private Providers providers; 59 | 60 | private OpenAPI openApi; 61 | private MediaType defaultMediaType; 62 | 63 | @PostConstruct 64 | private void init() { 65 | defaultMediaType = defaultMediaType == null ? extension.getDefaultMediaType() : defaultMediaType; 66 | } 67 | 68 | @Override 69 | public void filter(final ContainerRequestContext rc) { 70 | if (!HttpMethod.GET.equals(rc.getRequest().getMethod())) { 71 | return; 72 | } 73 | final String path = rc.getUriInfo().getPath(); 74 | if ("openapi".equals(path)) { 75 | final List mediaTypes = rc.getAcceptableMediaTypes(); 76 | rc.abortWith(Response.ok(openApi).type(selectType(mediaTypes)).build()); 77 | } 78 | if ("openapi.json".equals(path)) { 79 | rc.abortWith(Response.ok(openApi).type(APPLICATION_JSON_TYPE).build()); 80 | } 81 | if ("openapi.yml".equals(path) || "openapi.yaml".equals(path)) { 82 | rc.abortWith(Response.ok(openApi).type("text/vnd.yaml").build()); 83 | } 84 | } 85 | 86 | private MediaType selectType(final List mediaTypes) { 87 | if (mediaTypes.contains(APPLICATION_JSON_TYPE)) { 88 | return APPLICATION_JSON_TYPE; 89 | } 90 | if (mediaTypes.isEmpty()) { 91 | return defaultMediaType; 92 | } 93 | return mediaTypes.stream() 94 | .filter(it -> !WILDCARD_TYPE.equals(it)) 95 | .findFirst() 96 | .filter(it -> providers.getMessageBodyReader(OpenAPI.class, OpenAPI.class, NO_ANNOTATION, it) != null) 97 | .orElse(defaultMediaType); 98 | } 99 | 100 | @Context 101 | public void setApplication(final Application application) { 102 | this.openApi = extension.getOrCreateOpenAPI(application); 103 | } 104 | 105 | public void setDefaultMediaType(final MediaType defaultMediaType) { 106 | this.defaultMediaType = defaultMediaType; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/InfoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | 24 | import org.eclipse.microprofile.openapi.models.Extensible; 25 | import org.eclipse.microprofile.openapi.models.info.Contact; 26 | import org.eclipse.microprofile.openapi.models.info.Info; 27 | import org.eclipse.microprofile.openapi.models.info.License; 28 | 29 | @Vetoed 30 | public class InfoImpl implements Info { 31 | 32 | private Extensible _extensible = new ExtensibleImpl(); 33 | 34 | private Contact _contact; 35 | 36 | private String _description; 37 | 38 | private License _license; 39 | 40 | private String _termsOfService; 41 | 42 | private String _title; 43 | 44 | private String _version; 45 | 46 | @Override 47 | @JsonbTransient 48 | public Map getExtensions() { 49 | return _extensible.getExtensions(); 50 | } 51 | 52 | @Override 53 | public void setExtensions(final Map extensions) { 54 | _extensible.setExtensions(extensions); 55 | } 56 | 57 | @Override 58 | public Info addExtension(final String name, final Object value) { 59 | _extensible.addExtension(name, value); 60 | return this; 61 | } 62 | 63 | @Override 64 | public void removeExtension(final String name) { 65 | _extensible.removeExtension(name); 66 | } 67 | 68 | @Override 69 | public Contact getContact() { 70 | return _contact; 71 | } 72 | 73 | @Override 74 | public void setContact(final Contact _contact) { 75 | this._contact = _contact; 76 | } 77 | 78 | @Override 79 | public Info contact(final Contact _contact) { 80 | setContact(_contact); 81 | return this; 82 | } 83 | 84 | @Override 85 | public String getDescription() { 86 | return _description; 87 | } 88 | 89 | @Override 90 | public void setDescription(final String _description) { 91 | this._description = _description; 92 | } 93 | 94 | @Override 95 | public Info description(final String _description) { 96 | setDescription(_description); 97 | return this; 98 | } 99 | 100 | @Override 101 | public License getLicense() { 102 | return _license; 103 | } 104 | 105 | @Override 106 | public void setLicense(final License _license) { 107 | this._license = _license; 108 | } 109 | 110 | @Override 111 | public Info license(final License _license) { 112 | setLicense(_license); 113 | return this; 114 | } 115 | 116 | @Override 117 | public String getTermsOfService() { 118 | return _termsOfService; 119 | } 120 | 121 | @Override 122 | public void setTermsOfService(final String _termsOfService) { 123 | this._termsOfService = _termsOfService; 124 | } 125 | 126 | @Override 127 | public Info termsOfService(final String _termsOfService) { 128 | setTermsOfService(_termsOfService); 129 | return this; 130 | } 131 | 132 | @Override 133 | public String getTitle() { 134 | return _title; 135 | } 136 | 137 | @Override 138 | public void setTitle(final String _title) { 139 | this._title = _title; 140 | } 141 | 142 | @Override 143 | public Info title(final String _title) { 144 | setTitle(_title); 145 | return this; 146 | } 147 | 148 | @Override 149 | public String getVersion() { 150 | return _version; 151 | } 152 | 153 | @Override 154 | public void setVersion(final String _version) { 155 | this._version = _version; 156 | } 157 | 158 | @Override 159 | public Info version(final String _version) { 160 | setVersion(_version); 161 | return this; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/EncodingImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbTransient; 23 | import javax.json.bind.annotation.JsonbTypeAdapter; 24 | import javax.json.bind.annotation.JsonbTypeDeserializer; 25 | 26 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Deserializers; 27 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Serializers; 28 | import org.eclipse.microprofile.openapi.models.Extensible; 29 | import org.eclipse.microprofile.openapi.models.headers.Header; 30 | import org.eclipse.microprofile.openapi.models.media.Encoding; 31 | 32 | @Vetoed 33 | public class EncodingImpl implements Encoding { 34 | 35 | private Extensible _extensible = new ExtensibleImpl(); 36 | 37 | private Boolean _allowReserved; 38 | 39 | private String _contentType; 40 | 41 | private Boolean _explode; 42 | 43 | private Map _headers; 44 | 45 | private Style _style; 46 | 47 | @Override 48 | @JsonbTransient 49 | public Map getExtensions() { 50 | return _extensible.getExtensions(); 51 | } 52 | 53 | @Override 54 | public void setExtensions(final Map extensions) { 55 | _extensible.setExtensions(extensions); 56 | } 57 | 58 | @Override 59 | public Encoding addExtension(final String name, final Object value) { 60 | _extensible.addExtension(name, value); 61 | return this; 62 | } 63 | 64 | @Override 65 | public void removeExtension(final String name) { 66 | _extensible.removeExtension(name); 67 | } 68 | 69 | @Override 70 | public Boolean getAllowReserved() { 71 | return _allowReserved; 72 | } 73 | 74 | @Override 75 | public void setAllowReserved(final Boolean _allowReserved) { 76 | this._allowReserved = _allowReserved; 77 | } 78 | 79 | @Override 80 | public Encoding allowReserved(final Boolean _allowReserved) { 81 | setAllowReserved(_allowReserved); 82 | return this; 83 | } 84 | 85 | @Override 86 | public String getContentType() { 87 | return _contentType; 88 | } 89 | 90 | @Override 91 | public void setContentType(final String _contentType) { 92 | this._contentType = _contentType; 93 | } 94 | 95 | @Override 96 | public Encoding contentType(final String _contentType) { 97 | setContentType(_contentType); 98 | return this; 99 | } 100 | 101 | @Override 102 | public Boolean getExplode() { 103 | return _explode; 104 | } 105 | 106 | @Override 107 | public void setExplode(final Boolean _explode) { 108 | this._explode = _explode; 109 | } 110 | 111 | @Override 112 | public Encoding explode(final Boolean _explode) { 113 | setExplode(_explode); 114 | return this; 115 | } 116 | 117 | @Override 118 | public Map getHeaders() { 119 | return _headers; 120 | } 121 | 122 | @Override 123 | @JsonbTypeDeserializer(Deserializers.MapHeadersDeserializer.class) 124 | public void setHeaders(final Map _headers) { 125 | this._headers = _headers; 126 | } 127 | 128 | @Override 129 | public Encoding addHeader(final String key, final Header header) { 130 | if (header != null) { 131 | _headers.put(key, header); 132 | } 133 | return this; 134 | } 135 | 136 | @Override 137 | public void removeHeader(final String key) { 138 | _headers.remove(key); 139 | } 140 | 141 | @Override 142 | public Encoding headers(final Map _headers) { 143 | setHeaders(_headers); 144 | return this; 145 | } 146 | 147 | @Override 148 | @JsonbTypeAdapter(Serializers.EncodingStyleSerializer.class) 149 | public Style getStyle() { 150 | return _style; 151 | } 152 | 153 | @Override 154 | @JsonbTypeAdapter(Serializers.EncodingStyleSerializer.class) 155 | public void setStyle(final Style _style) { 156 | this._style = _style; 157 | } 158 | 159 | @Override 160 | public Encoding style(final Style _style) { 161 | setStyle(_style); 162 | return this; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/MediaTypeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | import javax.json.bind.annotation.JsonbTypeDeserializer; 25 | 26 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Deserializers; 27 | import org.eclipse.microprofile.openapi.models.Extensible; 28 | import org.eclipse.microprofile.openapi.models.examples.Example; 29 | import org.eclipse.microprofile.openapi.models.media.Encoding; 30 | import org.eclipse.microprofile.openapi.models.media.MediaType; 31 | import org.eclipse.microprofile.openapi.models.media.Schema; 32 | 33 | @Vetoed 34 | public class MediaTypeImpl implements MediaType { 35 | 36 | private Extensible _extensible = new ExtensibleImpl(); 37 | 38 | private Map _encoding; 39 | 40 | private Object _example; 41 | 42 | private Map _examples; 43 | 44 | private Schema _schema; 45 | 46 | @Override 47 | @JsonbTransient 48 | public Map getExtensions() { 49 | return _extensible.getExtensions(); 50 | } 51 | 52 | @Override 53 | public void setExtensions(final Map extensions) { 54 | _extensible.setExtensions(extensions); 55 | } 56 | 57 | @Override 58 | public MediaType addExtension(final String name, final Object value) { 59 | _extensible.addExtension(name, value); 60 | return this; 61 | } 62 | 63 | @Override 64 | public void removeExtension(final String name) { 65 | _extensible.removeExtension(name); 66 | } 67 | 68 | @Override 69 | public Map getEncoding() { 70 | return _encoding; 71 | } 72 | 73 | @Override 74 | @JsonbTypeDeserializer(Deserializers.MapEncodingsDeserializer.class) 75 | public void setEncoding(final Map _encoding) { 76 | this._encoding = _encoding; 77 | } 78 | 79 | @Override 80 | public MediaType encoding(final Map _encoding) { 81 | setEncoding(_encoding); 82 | return this; 83 | } 84 | 85 | @Override 86 | public MediaType addEncoding(final String key, final Encoding _encoding) { 87 | if (_encoding != null) { 88 | (this._encoding = this._encoding == null ? new LinkedHashMap<>() : this._encoding).put(key, _encoding); 89 | } 90 | return this; 91 | } 92 | 93 | @Override 94 | public void removeEncoding(final String key) { 95 | _encoding.remove(key); 96 | } 97 | 98 | @Override 99 | public Object getExample() { 100 | return _example; 101 | } 102 | 103 | @Override 104 | @JsonbTypeDeserializer(Deserializers.MapExamplesDeserializer.class) 105 | public void setExample(final Object _example) { 106 | this._example = _example; 107 | } 108 | 109 | @Override 110 | public MediaType example(final Object _example) { 111 | setExample(_example); 112 | return this; 113 | } 114 | 115 | @Override 116 | public Map getExamples() { 117 | return _examples; 118 | } 119 | 120 | @Override 121 | public void setExamples(final Map _examples) { 122 | this._examples = _examples; 123 | } 124 | 125 | @Override 126 | public MediaType examples(final Map _examples) { 127 | setExamples(_examples); 128 | return this; 129 | } 130 | 131 | @Override 132 | public MediaType addExample(final String key, final Example _examples) { 133 | if (_examples != null) { 134 | (this._examples = this._examples == null ? new LinkedHashMap<>() : this._examples).put(key, _examples); 135 | } 136 | return this; 137 | } 138 | 139 | @Override 140 | public void removeExample(final String key) { 141 | _examples.remove(key); 142 | } 143 | 144 | @Override 145 | public Schema getSchema() { 146 | return _schema != null ? _schema : (_schema = new SchemaImpl()); 147 | } 148 | 149 | @Override 150 | public void setSchema(final Schema _schema) { 151 | this._schema = _schema; 152 | } 153 | 154 | @Override 155 | public MediaType schema(final Schema _schema) { 156 | setSchema(_schema); 157 | return this; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/reflect/MethodElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.processor.reflect; 18 | 19 | import org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedMethodElement; 20 | import org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedTypeElement; 21 | 22 | import java.lang.annotation.Annotation; 23 | import java.lang.reflect.AnnotatedElement; 24 | import java.lang.reflect.Method; 25 | import java.lang.reflect.Type; 26 | import java.util.Collection; 27 | import java.util.LinkedList; 28 | import java.util.Objects; 29 | import java.util.stream.IntStream; 30 | import java.util.stream.Stream; 31 | 32 | import static java.util.function.Function.identity; 33 | import static java.util.stream.Collectors.toMap; 34 | 35 | public class MethodElement implements AnnotatedMethodElement { 36 | private static final Method[] NO_METHOD = new Method[0]; 37 | 38 | private final Method[] delegates; 39 | private Annotation[] annotations; 40 | 41 | public MethodElement(final Method method) { 42 | final Collection methods = new LinkedList<>(); 43 | methods.add(method); 44 | Stream.of(method.getDeclaringClass().getInterfaces()) 45 | .map(it -> { 46 | try { 47 | return it.getMethod(method.getName(), method.getParameterTypes()); 48 | } catch (final NoSuchMethodException e) { 49 | return null; 50 | } 51 | }) 52 | .filter(Objects::nonNull).forEach(methods::add); 53 | this.delegates = methods.toArray(NO_METHOD); 54 | } 55 | 56 | @Override 57 | public String getName() { 58 | return delegates[0].getName(); 59 | } 60 | 61 | @Override 62 | public Type getReturnType() { 63 | return delegates[0].getGenericReturnType(); 64 | } 65 | 66 | @Override 67 | public Class getDeclaringClass() { 68 | return delegates[0].getDeclaringClass(); 69 | } 70 | 71 | @Override 72 | public AnnotatedTypeElement[] getParameters() { 73 | final java.lang.reflect.Parameter[] parameters = delegates[0].getParameters(); 74 | return IntStream.range(0, parameters.length) 75 | .mapToObj(p -> new AnnotatedTypeElement() { 76 | private Annotation[] annotations; 77 | 78 | @Override 79 | public Type getType() { 80 | return parameters[p].getParameterizedType(); 81 | } 82 | 83 | @Override // todo: 84 | public T getAnnotation(final Class annotationClass) { 85 | return Stream.of(delegates) 86 | .map(m -> m.getParameters()[p]) 87 | .filter(it -> it.isAnnotationPresent(annotationClass)) 88 | .map(it -> it.getAnnotation(annotationClass)) 89 | .findFirst() 90 | .orElse(null); 91 | } 92 | 93 | @Override 94 | public Annotation[] getAnnotations() { 95 | return annotations == null ? annotations = mergeAnnotations(delegates) : annotations; 96 | } 97 | 98 | @Override 99 | public Annotation[] getDeclaredAnnotations() { 100 | return getAnnotations(); 101 | } 102 | }).toArray(AnnotatedTypeElement[]::new); 103 | } 104 | 105 | @Override 106 | public T getAnnotation(final Class annotationClass) { 107 | return Stream.of(delegates) 108 | .filter(d -> d.isAnnotationPresent(annotationClass)) 109 | .map(d -> d.getAnnotation(annotationClass)) 110 | .findFirst().orElse(null); 111 | } 112 | 113 | @Override 114 | public Annotation[] getAnnotations() { 115 | return annotations == null ? annotations = mergeAnnotations(delegates) : annotations; 116 | } 117 | 118 | @Override 119 | public Annotation[] getDeclaredAnnotations() { 120 | return getAnnotations(); 121 | } 122 | 123 | 124 | private static Annotation[] mergeAnnotations(final AnnotatedElement... element) { 125 | return Stream.of(element) 126 | .flatMap(i -> Stream.of(i.getAnnotations())) 127 | .collect(toMap(Annotation::annotationType, identity(), (a, b) -> a)) 128 | .values() 129 | .toArray(new Annotation[0]); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/codec/Deserializers.java: -------------------------------------------------------------------------------- 1 | package org.apache.geronimo.microprofile.openapi.impl.model.codec; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.Map; 6 | 7 | import javax.enterprise.inject.Vetoed; 8 | import javax.json.bind.serializer.DeserializationContext; 9 | import javax.json.bind.serializer.JsonbDeserializer; 10 | import javax.json.stream.JsonParser; 11 | 12 | import org.apache.geronimo.microprofile.openapi.impl.model.APIResponseImpl; 13 | import org.apache.geronimo.microprofile.openapi.impl.model.CallbackImpl; 14 | import org.apache.geronimo.microprofile.openapi.impl.model.EncodingImpl; 15 | import org.apache.geronimo.microprofile.openapi.impl.model.ExampleImpl; 16 | import org.apache.geronimo.microprofile.openapi.impl.model.HeaderImpl; 17 | import org.apache.geronimo.microprofile.openapi.impl.model.LinkImpl; 18 | import org.apache.geronimo.microprofile.openapi.impl.model.ParameterImpl; 19 | import org.apache.geronimo.microprofile.openapi.impl.model.RequestBodyImpl; 20 | import org.apache.geronimo.microprofile.openapi.impl.model.SchemaImpl; 21 | import org.apache.geronimo.microprofile.openapi.impl.model.SecuritySchemeImpl; 22 | import org.eclipse.microprofile.openapi.models.callbacks.Callback; 23 | import org.eclipse.microprofile.openapi.models.examples.Example; 24 | import org.eclipse.microprofile.openapi.models.headers.Header; 25 | import org.eclipse.microprofile.openapi.models.links.Link; 26 | import org.eclipse.microprofile.openapi.models.media.Encoding; 27 | import org.eclipse.microprofile.openapi.models.media.Schema; 28 | import org.eclipse.microprofile.openapi.models.parameters.Parameter; 29 | import org.eclipse.microprofile.openapi.models.parameters.RequestBody; 30 | import org.eclipse.microprofile.openapi.models.responses.APIResponse; 31 | import org.eclipse.microprofile.openapi.models.security.SecurityScheme; 32 | 33 | @Vetoed 34 | public final class Deserializers { 35 | 36 | private Deserializers() { 37 | // no-op 38 | } 39 | 40 | private static Type mapType(final Class value) { 41 | final Type[] args = new Type[] { String.class, value }; 42 | return new ParameterizedType() { 43 | 44 | @Override 45 | public Type[] getActualTypeArguments() { 46 | return args; 47 | } 48 | 49 | @Override 50 | public Type getRawType() { 51 | return Map.class; 52 | } 53 | 54 | @Override 55 | public Type getOwnerType() { 56 | return null; 57 | }; 58 | }; 59 | } 60 | 61 | @Vetoed 62 | public static class MapHeadersDeserializer extends BaseDeserializer> { 63 | public MapHeadersDeserializer() { 64 | super(mapType(HeaderImpl.class)); 65 | } 66 | } 67 | 68 | @Vetoed 69 | public static class MapLinksDeserializer extends BaseDeserializer> { 70 | public MapLinksDeserializer() { 71 | super(mapType(LinkImpl.class)); 72 | } 73 | } 74 | 75 | @Vetoed 76 | public static class MapCallbacksDeserializer extends BaseDeserializer> { 77 | public MapCallbacksDeserializer() { 78 | super(mapType(CallbackImpl.class)); 79 | } 80 | } 81 | 82 | @Vetoed 83 | public static class MapExamplesDeserializer extends BaseDeserializer> { 84 | public MapExamplesDeserializer() { 85 | super(mapType(ExampleImpl.class)); 86 | } 87 | } 88 | 89 | @Vetoed 90 | public static class MapParametersDeserializer extends BaseDeserializer> { 91 | public MapParametersDeserializer() { 92 | super(mapType(ParameterImpl.class)); 93 | } 94 | } 95 | 96 | @Vetoed 97 | public static class MapRequestBodiesDeserializer extends BaseDeserializer> { 98 | public MapRequestBodiesDeserializer() { 99 | super(mapType(RequestBodyImpl.class)); 100 | } 101 | } 102 | 103 | @Vetoed 104 | public static class MapAPIResponsesDeserializer extends BaseDeserializer> { 105 | public MapAPIResponsesDeserializer() { 106 | super(mapType(APIResponseImpl.class)); 107 | } 108 | } 109 | 110 | @Vetoed 111 | public static class MapSchemasDeserializer extends BaseDeserializer> { 112 | public MapSchemasDeserializer() { 113 | super(mapType(SchemaImpl.class)); 114 | } 115 | } 116 | 117 | @Vetoed 118 | public static class MapSecuritySchemesDeserializer extends BaseDeserializer> { 119 | public MapSecuritySchemesDeserializer() { 120 | super(mapType(SecuritySchemeImpl.class)); 121 | } 122 | } 123 | 124 | @Vetoed 125 | public static class MapEncodingsDeserializer extends BaseDeserializer> { 126 | public MapEncodingsDeserializer() { 127 | super(mapType(EncodingImpl.class)); 128 | } 129 | } 130 | 131 | @Vetoed 132 | protected static class BaseDeserializer implements JsonbDeserializer { 133 | 134 | private final Type actualType; 135 | 136 | protected BaseDeserializer(final Type actualType) { 137 | this.actualType = actualType; 138 | } 139 | 140 | @Override 141 | public T deserialize(final JsonParser parser, final DeserializationContext ctx, final Type rtType) { 142 | return ctx.deserialize(actualType, parser); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/APIResponseImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | import javax.json.bind.annotation.JsonbTypeDeserializer; 25 | 26 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Deserializers; 27 | import org.eclipse.microprofile.openapi.models.Extensible; 28 | import org.eclipse.microprofile.openapi.models.headers.Header; 29 | import org.eclipse.microprofile.openapi.models.links.Link; 30 | import org.eclipse.microprofile.openapi.models.media.Content; 31 | import org.eclipse.microprofile.openapi.models.responses.APIResponse; 32 | 33 | @Vetoed 34 | public class APIResponseImpl implements APIResponse { 35 | 36 | private Extensible _extensible = new ExtensibleImpl(); 37 | 38 | private Content _content; 39 | 40 | private String _description; 41 | 42 | private Map _headers; 43 | 44 | private Map _links; 45 | 46 | private String _ref; 47 | 48 | @Override 49 | @JsonbTransient 50 | public Map getExtensions() { 51 | return _extensible.getExtensions(); 52 | } 53 | 54 | @Override 55 | public void setExtensions(final Map extensions) { 56 | _extensible.setExtensions(extensions); 57 | } 58 | 59 | @Override 60 | public APIResponse addExtension(final String name, final Object value) { 61 | _extensible.addExtension(name, value); 62 | return this; 63 | } 64 | 65 | @Override 66 | public void removeHeader(final String name) { 67 | _headers.remove(name); 68 | } 69 | 70 | @Override 71 | public void removeLink(final String name) { 72 | _links.remove(name); 73 | } 74 | 75 | @Override 76 | public void removeExtension(final String name) { 77 | _extensible.removeExtension(name); 78 | } 79 | 80 | @Override 81 | public Content getContent() { 82 | return _content; 83 | } 84 | 85 | @Override 86 | public void setContent(final Content _content) { 87 | this._content = _content; 88 | } 89 | 90 | @Override 91 | public APIResponse content(final Content _content) { 92 | setContent(_content); 93 | return this; 94 | } 95 | 96 | @Override 97 | public String getDescription() { 98 | return _description; 99 | } 100 | 101 | @Override 102 | public void setDescription(final String _description) { 103 | this._description = _description; 104 | } 105 | 106 | @Override 107 | public APIResponse description(final String _description) { 108 | setDescription(_description); 109 | return this; 110 | } 111 | 112 | @Override 113 | public Map getHeaders() { 114 | return _headers; 115 | } 116 | 117 | @Override 118 | @JsonbTypeDeserializer(Deserializers.MapHeadersDeserializer.class) 119 | public void setHeaders(final Map _headers) { 120 | this._headers = _headers; 121 | } 122 | 123 | @Override 124 | public APIResponse headers(final Map _headers) { 125 | setHeaders(_headers); 126 | return this; 127 | } 128 | 129 | @Override 130 | public APIResponse addHeader(final String key, final Header _headers) { 131 | if (_headers != null) { 132 | (this._headers = this._headers == null ? new LinkedHashMap<>() : this._headers).put(key, _headers); 133 | } 134 | return this; 135 | } 136 | 137 | @Override 138 | public Map getLinks() { 139 | return _links; 140 | } 141 | 142 | @Override 143 | @JsonbTypeDeserializer(Deserializers.MapLinksDeserializer.class) 144 | public void setLinks(final Map _links) { 145 | this._links = _links; 146 | } 147 | 148 | @Override 149 | public APIResponse links(final Map _links) { 150 | setLinks(_links); 151 | return this; 152 | } 153 | 154 | @Override 155 | public APIResponse addLink(final String key, final Link _links) { 156 | if (_links != null) { 157 | (this._links = this._links == null ? new LinkedHashMap<>() : this._links).put(key, _links); 158 | } 159 | return this; 160 | } 161 | 162 | @Override 163 | public String getRef() { 164 | return _ref; 165 | } 166 | 167 | @Override 168 | public void setRef(final String _ref) { 169 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/responses/" + _ref); 170 | } 171 | 172 | @Override 173 | public APIResponse ref(final String _ref) { 174 | setRef(_ref); 175 | return this; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/LinkImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbProperty; 24 | import javax.json.bind.annotation.JsonbTransient; 25 | 26 | import org.eclipse.microprofile.openapi.models.Extensible; 27 | import org.eclipse.microprofile.openapi.models.links.Link; 28 | import org.eclipse.microprofile.openapi.models.servers.Server; 29 | 30 | @Vetoed 31 | public class LinkImpl implements Link { 32 | 33 | private Extensible _extensible = new ExtensibleImpl(); 34 | 35 | private String _description; 36 | 37 | private String _operationId; 38 | 39 | private String _operationRef; 40 | 41 | private Map _parameters; 42 | 43 | private String _ref; 44 | 45 | private Object _requestBody; 46 | 47 | private Server _server; 48 | 49 | @Override 50 | @JsonbTransient 51 | public Map getExtensions() { 52 | return _extensible.getExtensions(); 53 | } 54 | 55 | @Override 56 | public void setExtensions(final Map extensions) { 57 | _extensible.setExtensions(extensions); 58 | } 59 | 60 | @Override 61 | public Link addExtension(final String name, final Object value) { 62 | _extensible.addExtension(name, value); 63 | return this; 64 | } 65 | 66 | @Override 67 | public void removeExtension(final String name) { 68 | _extensible.removeExtension(name); 69 | } 70 | 71 | @Override 72 | public void removeParameter(final String name) { 73 | _parameters.remove(name); 74 | } 75 | 76 | @Override 77 | public String getDescription() { 78 | return _description; 79 | } 80 | 81 | @Override 82 | public void setDescription(final String _description) { 83 | this._description = _description; 84 | } 85 | 86 | @Override 87 | public Link description(final String _description) { 88 | setDescription(_description); 89 | return this; 90 | } 91 | 92 | @Override 93 | public String getOperationId() { 94 | return _operationId; 95 | } 96 | 97 | @Override 98 | public void setOperationId(final String _operationId) { 99 | this._operationId = _operationId; 100 | } 101 | 102 | @Override 103 | public Link operationId(final String _operationId) { 104 | setOperationId(_operationId); 105 | return this; 106 | } 107 | 108 | @Override 109 | public String getOperationRef() { 110 | return _operationRef; 111 | } 112 | 113 | @Override 114 | public void setOperationRef(final String _operationRef) { 115 | this._operationRef = _operationRef; 116 | } 117 | 118 | @Override 119 | public Link operationRef(final String _operationRef) { 120 | setOperationRef(_operationRef); 121 | return this; 122 | } 123 | 124 | @Override 125 | public Map getParameters() { 126 | return _parameters; 127 | } 128 | 129 | @Override 130 | public void setParameters(final Map _parameters) { 131 | this._parameters = _parameters; 132 | } 133 | 134 | @Override 135 | public Link parameters(final Map _parameters) { 136 | setParameters(_parameters); 137 | return this; 138 | } 139 | 140 | @Override 141 | public Link addParameter(final String key, final Object _parameters) { 142 | if (_parameters != null) { 143 | (this._parameters = this._parameters == null ? new LinkedHashMap<>() : this._parameters).put(key, _parameters); 144 | } 145 | return this; 146 | } 147 | 148 | @Override 149 | @JsonbProperty("$ref") 150 | public String getRef() { 151 | return _ref; 152 | } 153 | 154 | @Override 155 | @JsonbProperty("$ref") 156 | public void setRef(final String _ref) { 157 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/links/" + _ref); 158 | } 159 | 160 | @Override 161 | public Link ref(final String _ref) { 162 | setRef(_ref); 163 | return this; 164 | } 165 | 166 | @Override 167 | public Object getRequestBody() { 168 | return _requestBody; 169 | } 170 | 171 | @Override 172 | public void setRequestBody(final Object _requestBody) { 173 | this._requestBody = _requestBody; 174 | } 175 | 176 | @Override 177 | public Link requestBody(final Object _requestBody) { 178 | setRequestBody(_requestBody); 179 | return this; 180 | } 181 | 182 | @Override 183 | public Server getServer() { 184 | return _server; 185 | } 186 | 187 | @Override 188 | public void setServer(final Server _server) { 189 | this._server = _server; 190 | } 191 | 192 | @Override 193 | public Link server(final Server _server) { 194 | setServer(_server); 195 | return this; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/codec/Serializers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model.codec; 18 | 19 | import static java.util.Locale.ROOT; 20 | 21 | import java.math.BigDecimal; 22 | import java.util.stream.Stream; 23 | 24 | import javax.enterprise.inject.Vetoed; 25 | import javax.json.bind.adapter.JsonbAdapter; 26 | import javax.json.bind.serializer.JsonbSerializer; 27 | import javax.json.bind.serializer.SerializationContext; 28 | import javax.json.stream.JsonGenerator; 29 | 30 | import org.eclipse.microprofile.openapi.models.Extensible; 31 | import org.eclipse.microprofile.openapi.models.headers.Header; 32 | import org.eclipse.microprofile.openapi.models.media.Encoding; 33 | import org.eclipse.microprofile.openapi.models.media.Schema; 34 | import org.eclipse.microprofile.openapi.models.parameters.Parameter; 35 | import org.eclipse.microprofile.openapi.models.security.SecurityScheme; 36 | 37 | @Vetoed 38 | public final class Serializers { 39 | 40 | private Serializers() { 41 | // no-op 42 | } 43 | 44 | @Vetoed // truncate longs/integers at serialization time 45 | public static class BigDecimalSerializer implements JsonbAdapter { 46 | @Override 47 | public Number adaptToJson(final BigDecimal obj) { 48 | if (obj.remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) == 0) { 49 | return obj.longValueExact(); 50 | } 51 | return obj; 52 | } 53 | 54 | @Override 55 | public BigDecimal adaptFromJson(final Number obj) { 56 | return BigDecimal.class.isInstance(obj) ? BigDecimal.class.cast(obj) : BigDecimal.valueOf(obj.doubleValue()); 57 | } 58 | } 59 | 60 | @Vetoed 61 | private static abstract class EnumSerializer> implements JsonbAdapter { 62 | 63 | private final Class type; 64 | 65 | protected EnumSerializer(final Class type) { 66 | this.type = type; 67 | } 68 | 69 | @Override 70 | public String adaptToJson(final E obj) { 71 | return obj.toString(); 72 | } 73 | 74 | @Override 75 | public E adaptFromJson(final String obj) { 76 | try { 77 | return Enum.valueOf(type, obj.toUpperCase(ROOT)); 78 | } catch (final IllegalArgumentException iae) { 79 | return Stream.of(type.getEnumConstants()) 80 | .filter(it -> it.toString().equals(obj)).findFirst() 81 | .orElseThrow(() -> iae); 82 | } 83 | } 84 | } 85 | 86 | @Vetoed 87 | public static class EncodingStyleSerializer extends EnumSerializer implements JsonbAdapter { 88 | 89 | public EncodingStyleSerializer() { 90 | super(Encoding.Style.class); 91 | } 92 | } 93 | 94 | @Vetoed 95 | public static class HeaderStyleSerializer extends EnumSerializer implements JsonbAdapter { 96 | 97 | public HeaderStyleSerializer() { 98 | super(Header.Style.class); 99 | } 100 | } 101 | 102 | @Vetoed 103 | public static class ParameterStyleSerializer extends EnumSerializer implements JsonbAdapter { 104 | 105 | public ParameterStyleSerializer() { 106 | super(Parameter.Style.class); 107 | } 108 | } 109 | 110 | @Vetoed 111 | public static class SecuritySchemeTypeSerializer extends EnumSerializer implements JsonbAdapter { 112 | 113 | public SecuritySchemeTypeSerializer() { 114 | super(SecurityScheme.Type.class); 115 | } 116 | } 117 | 118 | @Vetoed 119 | public static class SecuritySchemeInSerializer extends EnumSerializer implements JsonbAdapter { 120 | 121 | public SecuritySchemeInSerializer() { 122 | super(SecurityScheme.In.class); 123 | } 124 | } 125 | 126 | @Vetoed 127 | public static class InSerializer extends EnumSerializer implements JsonbAdapter { 128 | 129 | public InSerializer() { 130 | super(Parameter.In.class); 131 | } 132 | } 133 | 134 | @Vetoed 135 | public static class SchemaTypeSerializer extends EnumSerializer 136 | implements JsonbAdapter { 137 | 138 | public SchemaTypeSerializer() { 139 | super(Schema.SchemaType.class); 140 | } 141 | } 142 | 143 | @Vetoed 144 | public static class ExtensionSerializer> implements JsonbSerializer { 145 | @Override 146 | public void serialize(final T t, final JsonGenerator jsonGenerator, final SerializationContext serializationContext) { 147 | serializationContext.serialize(t, jsonGenerator); 148 | if (t.getExtensions() != null) { 149 | t.getExtensions().forEach((k, v) -> serializationContext.serialize(k, v, jsonGenerator)); 150 | } 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /geronimo-openapi-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | geronimo-openapi 21 | org.apache.geronimo 22 | 1.0.15-SNAPSHOT 23 | 24 | 4.0.0 25 | 26 | geronimo-openapi-maven-plugin 27 | maven-plugin 28 | Geronimo OpenAPI :: Maven Plugin 29 | 30 | 31 | 3.3.9 32 | 33 | 34 | 35 | 36 | org.eclipse.microprofile.openapi 37 | microprofile-openapi-api 38 | compile 39 | 40 | 41 | org.apache.geronimo.specs 42 | geronimo-jaxrs_2.0_spec 43 | compile 44 | 45 | 46 | org.apache.geronimo.specs 47 | geronimo-interceptor_1.2_spec 48 | compile 49 | 50 | 51 | org.apache.geronimo.specs 52 | geronimo-atinject_1.0_spec 53 | compile 54 | 55 | 56 | org.apache.geronimo.specs 57 | geronimo-jcdi_2.0_spec 58 | compile 59 | 60 | 61 | org.apache.geronimo.specs 62 | geronimo-annotation_1.3_spec 63 | compile 64 | 65 | 66 | org.eclipse.microprofile.config 67 | microprofile-config-api 68 | compile 69 | 70 | 71 | org.apache.geronimo.specs 72 | geronimo-jsonb_1.0_spec 73 | compile 74 | 75 | 76 | org.apache.geronimo.specs 77 | geronimo-json_1.1_spec 78 | compile 79 | 80 | 81 | org.apache.tomcat 82 | tomcat-servlet-api 83 | compile 84 | 85 | 86 | org.apache.geronimo 87 | geronimo-openapi-impl 88 | ${project.version} 89 | 90 | 91 | org.apache.maven.plugin-tools 92 | maven-plugin-annotations 93 | 3.5 94 | 95 | 96 | org.apache.maven 97 | maven-plugin-api 98 | ${mvn.version} 99 | 100 | 101 | org.apache.maven 102 | maven-core 103 | ${mvn.version} 104 | 105 | 106 | org.apache.johnzon 107 | johnzon-jsonb 108 | ${johnzon.version} 109 | 110 | 111 | org.apache.xbean 112 | xbean-finder-shaded 113 | 4.18 114 | 115 | 116 | 117 | junit 118 | junit 119 | test 120 | 121 | 122 | 123 | 124 | 125 | 126 | org.apache.maven.plugins 127 | maven-plugin-plugin 128 | 3.5 129 | 130 | 131 | mojo-descriptor 132 | 133 | descriptor 134 | helpmojo 135 | 136 | 137 | 138 | 139 | geronimo-openapi 140 | true 141 | 142 | 143 | 144 | org.apache.maven.plugins 145 | maven-invoker-plugin 146 | 3.1.0 147 | 148 | 149 | clean 150 | install 151 | 152 | verify.bsh 153 | 154 | 155 | 156 | 157 | install 158 | run 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | org.apache.maven.plugins 170 | maven-plugin-plugin 171 | 3.5.1 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/SecuritySchemeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.Map; 20 | 21 | import javax.enterprise.inject.Vetoed; 22 | import javax.json.bind.annotation.JsonbProperty; 23 | import javax.json.bind.annotation.JsonbTransient; 24 | import javax.json.bind.annotation.JsonbTypeAdapter; 25 | 26 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Serializers; 27 | import org.eclipse.microprofile.openapi.models.Extensible; 28 | import org.eclipse.microprofile.openapi.models.security.OAuthFlows; 29 | import org.eclipse.microprofile.openapi.models.security.SecurityScheme; 30 | 31 | @Vetoed 32 | public class SecuritySchemeImpl implements SecurityScheme { 33 | 34 | private Extensible _extensible = new ExtensibleImpl(); 35 | 36 | private String _bearerFormat; 37 | 38 | private String _description; 39 | 40 | private OAuthFlows _flows; 41 | 42 | private In _in; 43 | 44 | private String _name; 45 | 46 | private String _openIdConnectUrl; 47 | 48 | private String _ref; 49 | 50 | private String _scheme; 51 | 52 | private Type _type; 53 | 54 | @Override 55 | @JsonbTransient 56 | public Map getExtensions() { 57 | return _extensible.getExtensions(); 58 | } 59 | 60 | @Override 61 | public void setExtensions(final Map extensions) { 62 | _extensible.setExtensions(extensions); 63 | } 64 | 65 | @Override 66 | public SecurityScheme addExtension(final String name, final Object value) { 67 | _extensible.addExtension(name, value); 68 | return this; 69 | } 70 | 71 | @Override 72 | public void removeExtension(final String name) { 73 | _extensible.removeExtension(name); 74 | } 75 | 76 | @Override 77 | public String getBearerFormat() { 78 | return _bearerFormat; 79 | } 80 | 81 | @Override 82 | public void setBearerFormat(final String _bearerFormat) { 83 | this._bearerFormat = _bearerFormat; 84 | } 85 | 86 | @Override 87 | public SecurityScheme bearerFormat(final String _bearerFormat) { 88 | setBearerFormat(_bearerFormat); 89 | return this; 90 | } 91 | 92 | @Override 93 | public String getDescription() { 94 | return _description; 95 | } 96 | 97 | @Override 98 | public void setDescription(final String _description) { 99 | this._description = _description; 100 | } 101 | 102 | @Override 103 | public SecurityScheme description(final String _description) { 104 | setDescription(_description); 105 | return this; 106 | } 107 | 108 | @Override 109 | public OAuthFlows getFlows() { 110 | return _flows; 111 | } 112 | 113 | @Override 114 | public void setFlows(final OAuthFlows _flows) { 115 | this._flows = _flows; 116 | } 117 | 118 | @Override 119 | public SecurityScheme flows(final OAuthFlows _flows) { 120 | setFlows(_flows); 121 | return this; 122 | } 123 | 124 | @Override 125 | @JsonbTypeAdapter(Serializers.SecuritySchemeInSerializer.class) 126 | public In getIn() { 127 | return _in; 128 | } 129 | 130 | @Override 131 | @JsonbTypeAdapter(Serializers.SecuritySchemeInSerializer.class) 132 | public void setIn(final In _in) { 133 | this._in = _in; 134 | } 135 | 136 | @Override 137 | public SecurityScheme in(final In _in) { 138 | setIn(_in); 139 | return this; 140 | } 141 | 142 | @Override 143 | public String getName() { 144 | return _name; 145 | } 146 | 147 | @Override 148 | public void setName(final String _name) { 149 | this._name = _name; 150 | } 151 | 152 | @Override 153 | public SecurityScheme name(final String _name) { 154 | setName(_name); 155 | return this; 156 | } 157 | 158 | @Override 159 | public String getOpenIdConnectUrl() { 160 | return _openIdConnectUrl; 161 | } 162 | 163 | @Override 164 | public void setOpenIdConnectUrl(final String _openIdConnectUrl) { 165 | this._openIdConnectUrl = _openIdConnectUrl; 166 | } 167 | 168 | @Override 169 | public SecurityScheme openIdConnectUrl(final String _openIdConnectUrl) { 170 | setOpenIdConnectUrl(_openIdConnectUrl); 171 | return this; 172 | } 173 | 174 | @Override 175 | @JsonbProperty("$ref") 176 | public String getRef() { 177 | return _ref; 178 | } 179 | 180 | @Override 181 | @JsonbProperty("$ref") 182 | public void setRef(final String _ref) { 183 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/securitySchemes/" + _ref); 184 | } 185 | 186 | @Override 187 | public SecurityScheme ref(final String _ref) { 188 | setRef(_ref); 189 | return this; 190 | } 191 | 192 | @Override 193 | public String getScheme() { 194 | return _scheme; 195 | } 196 | 197 | @Override 198 | public void setScheme(final String _scheme) { 199 | this._scheme = _scheme; 200 | } 201 | 202 | @Override 203 | public SecurityScheme scheme(final String _scheme) { 204 | setScheme(_scheme); 205 | return this; 206 | } 207 | 208 | @Override 209 | @JsonbTypeAdapter(Serializers.SecuritySchemeTypeSerializer.class) 210 | public Type getType() { 211 | return _type; 212 | } 213 | 214 | @Override 215 | @JsonbTypeAdapter(Serializers.SecuritySchemeTypeSerializer.class) 216 | public void setType(final Type _type) { 217 | this._type = _type; 218 | } 219 | 220 | @Override 221 | public SecurityScheme type(final Type _type) { 222 | setType(_type); 223 | return this; 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/OpenAPIImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import static java.util.stream.Collectors.toList; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import javax.enterprise.inject.Vetoed; 26 | import javax.json.bind.annotation.JsonbTransient; 27 | 28 | import org.eclipse.microprofile.openapi.models.Components; 29 | import org.eclipse.microprofile.openapi.models.Extensible; 30 | import org.eclipse.microprofile.openapi.models.ExternalDocumentation; 31 | import org.eclipse.microprofile.openapi.models.OpenAPI; 32 | import org.eclipse.microprofile.openapi.models.PathItem; 33 | import org.eclipse.microprofile.openapi.models.Paths; 34 | import org.eclipse.microprofile.openapi.models.info.Info; 35 | import org.eclipse.microprofile.openapi.models.security.SecurityRequirement; 36 | import org.eclipse.microprofile.openapi.models.servers.Server; 37 | import org.eclipse.microprofile.openapi.models.tags.Tag; 38 | 39 | @Vetoed 40 | public class OpenAPIImpl implements OpenAPI { 41 | 42 | private Extensible _extensible = new ExtensibleImpl(); 43 | 44 | private Components _components; 45 | 46 | private ExternalDocumentation _externalDocs; 47 | 48 | private Info _info; 49 | 50 | private String _openapi = "3.0.1"; 51 | 52 | private Paths _paths; 53 | 54 | private List _security; 55 | 56 | private List _servers; 57 | 58 | private List _tags; 59 | 60 | @Override 61 | @JsonbTransient 62 | public Map getExtensions() { 63 | return _extensible.getExtensions(); 64 | } 65 | 66 | @Override 67 | public void setExtensions(final Map extensions) { 68 | _extensible.setExtensions(extensions); 69 | } 70 | 71 | @Override 72 | public OpenAPI addExtension(final String name, final Object value) { 73 | _extensible.addExtension(name, value); 74 | return this; 75 | } 76 | 77 | @Override 78 | public void removeExtension(final String name) { 79 | _extensible.removeExtension(name); 80 | } 81 | 82 | @Override 83 | public void removeServer(final Server server) { 84 | _servers.remove(server); 85 | } 86 | 87 | @Override 88 | public void removeSecurityRequirement(final SecurityRequirement securityRequirement) { 89 | _security.remove(securityRequirement); 90 | } 91 | 92 | @Override 93 | public void removeTag(final Tag tag) { 94 | _tags.remove(tag); 95 | } 96 | 97 | @Override 98 | public Components getComponents() { 99 | return _components; 100 | } 101 | 102 | @Override 103 | public void setComponents(final Components _components) { 104 | this._components = _components; 105 | } 106 | 107 | @Override 108 | public OpenAPI components(final Components _components) { 109 | setComponents(_components); 110 | return this; 111 | } 112 | 113 | @Override 114 | public ExternalDocumentation getExternalDocs() { 115 | return _externalDocs; 116 | } 117 | 118 | @Override 119 | public void setExternalDocs(final ExternalDocumentation _externalDocs) { 120 | this._externalDocs = _externalDocs; 121 | } 122 | 123 | @Override 124 | public OpenAPI externalDocs(final ExternalDocumentation _externalDocs) { 125 | setExternalDocs(_externalDocs); 126 | return this; 127 | } 128 | 129 | @Override 130 | public Info getInfo() { 131 | return _info; 132 | } 133 | 134 | @Override 135 | public void setInfo(final Info _info) { 136 | this._info = _info; 137 | } 138 | 139 | @Override 140 | public OpenAPI info(final Info _info) { 141 | setInfo(_info); 142 | return this; 143 | } 144 | 145 | @Override 146 | public String getOpenapi() { 147 | return _openapi; 148 | } 149 | 150 | @Override 151 | public void setOpenapi(final String _openapi) { 152 | this._openapi = _openapi; 153 | } 154 | 155 | @Override 156 | public OpenAPI openapi(final String _openapi) { 157 | setOpenapi(_openapi); 158 | return this; 159 | } 160 | 161 | @Override 162 | public Paths getPaths() { 163 | return _paths; 164 | } 165 | 166 | @Override 167 | public void setPaths(final Paths _paths) { 168 | this._paths = _paths; 169 | } 170 | 171 | @Override 172 | public OpenAPI paths(final Paths _paths) { 173 | setPaths(_paths); 174 | return this; 175 | } 176 | 177 | @Override 178 | public List getSecurity() { 179 | return _security; 180 | } 181 | 182 | @Override 183 | public void setSecurity(final List _security) { 184 | this._security = _security; 185 | } 186 | 187 | @Override 188 | public OpenAPI security(final List _security) { 189 | setSecurity(_security); 190 | return this; 191 | } 192 | 193 | @Override 194 | public OpenAPI addSecurityRequirement(final SecurityRequirement _security) { 195 | (this._security = this._security == null ? new ArrayList<>() : this._security).add(_security); 196 | return this; 197 | } 198 | 199 | @Override 200 | public List getServers() { 201 | return _servers; 202 | } 203 | 204 | @Override 205 | public void setServers(final List _servers) { 206 | this._servers = _servers; 207 | } 208 | 209 | @Override 210 | public OpenAPI servers(final List _servers) { 211 | setServers(_servers); 212 | return this; 213 | } 214 | 215 | @Override 216 | public OpenAPI addServer(final Server _servers) { 217 | (this._servers = this._servers == null ? new ArrayList<>() : this._servers).add(_servers); 218 | return this; 219 | } 220 | 221 | @Override 222 | public List getTags() { 223 | return _tags; 224 | } 225 | 226 | @Override 227 | public void setTags(final List _tags) { 228 | this._tags = _tags == null ? null : _tags.stream().distinct().collect(toList()); 229 | } 230 | 231 | @Override 232 | public OpenAPI tags(final List _tags) { 233 | setTags(_tags); 234 | return this; 235 | } 236 | 237 | @Override 238 | public OpenAPI addTag(final Tag _tags) { 239 | if (this._tags == null) { 240 | this._tags = new ArrayList<>(); 241 | } 242 | if (!this._tags.contains(_tags)) { 243 | this._tags.add(_tags); 244 | } 245 | return this; 246 | } 247 | 248 | @Override 249 | public OpenAPI path(final String name, final PathItem path) { 250 | (_paths = this._paths == null ? new PathsImpl() : this._paths).addPathItem(name, path); 251 | return this; 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/HeaderImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.model; 18 | 19 | import java.util.LinkedHashMap; 20 | import java.util.Map; 21 | 22 | import javax.enterprise.inject.Vetoed; 23 | import javax.json.bind.annotation.JsonbProperty; 24 | import javax.json.bind.annotation.JsonbTransient; 25 | import javax.json.bind.annotation.JsonbTypeAdapter; 26 | import javax.json.bind.annotation.JsonbTypeDeserializer; 27 | 28 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Deserializers; 29 | import org.apache.geronimo.microprofile.openapi.impl.model.codec.Serializers; 30 | import org.eclipse.microprofile.openapi.models.Extensible; 31 | import org.eclipse.microprofile.openapi.models.examples.Example; 32 | import org.eclipse.microprofile.openapi.models.headers.Header; 33 | import org.eclipse.microprofile.openapi.models.media.Content; 34 | import org.eclipse.microprofile.openapi.models.media.Schema; 35 | 36 | @Vetoed 37 | public class HeaderImpl implements Header { 38 | 39 | private Extensible _extensible = new ExtensibleImpl(); 40 | 41 | private Boolean _allowEmptyValue; 42 | 43 | private Content _content; 44 | 45 | private Boolean _deprecated; 46 | 47 | private String _description; 48 | 49 | private Object _example; 50 | 51 | private Map _examples; 52 | 53 | private Boolean _explode; 54 | 55 | private String _ref; 56 | 57 | private Boolean _required; 58 | 59 | private Schema _schema; 60 | 61 | private Style _style; 62 | 63 | @Override 64 | @JsonbTransient 65 | public Map getExtensions() { 66 | return _extensible.getExtensions(); 67 | } 68 | 69 | @Override 70 | public void setExtensions(final Map extensions) { 71 | _extensible.setExtensions(extensions); 72 | } 73 | 74 | @Override 75 | public Header addExtension(final String name, final Object value) { 76 | _extensible.addExtension(name, value); 77 | return this; 78 | } 79 | 80 | @Override 81 | public void removeExample(final String key) { 82 | _examples.remove(key); 83 | } 84 | 85 | @Override 86 | public void removeExtension(final String name) { 87 | _extensible.removeExtension(name); 88 | } 89 | 90 | @Override 91 | public Boolean getAllowEmptyValue() { 92 | return _allowEmptyValue; 93 | } 94 | 95 | @Override 96 | public void setAllowEmptyValue(final Boolean _allowEmptyValue) { 97 | this._allowEmptyValue = _allowEmptyValue; 98 | } 99 | 100 | @Override 101 | public Header allowEmptyValue(final Boolean _allowEmptyValue) { 102 | setAllowEmptyValue(_allowEmptyValue); 103 | return this; 104 | } 105 | 106 | @Override 107 | public Content getContent() { 108 | return _content; 109 | } 110 | 111 | @Override 112 | public void setContent(final Content _content) { 113 | this._content = _content; 114 | } 115 | 116 | @Override 117 | public Header content(final Content _content) { 118 | setContent(_content); 119 | return this; 120 | } 121 | 122 | @Override 123 | public Boolean getDeprecated() { 124 | return _deprecated; 125 | } 126 | 127 | @Override 128 | public void setDeprecated(final Boolean _deprecated) { 129 | this._deprecated = _deprecated; 130 | } 131 | 132 | @Override 133 | public Header deprecated(final Boolean _deprecated) { 134 | setDeprecated(_deprecated); 135 | return this; 136 | } 137 | 138 | @Override 139 | public String getDescription() { 140 | return _description; 141 | } 142 | 143 | @Override 144 | public void setDescription(final String _description) { 145 | this._description = _description; 146 | } 147 | 148 | @Override 149 | public Header description(final String _description) { 150 | setDescription(_description); 151 | return this; 152 | } 153 | 154 | @Override 155 | public Object getExample() { 156 | return _example; 157 | } 158 | 159 | @Override 160 | @JsonbTypeDeserializer(Deserializers.MapExamplesDeserializer.class) 161 | public void setExample(final Object _example) { 162 | this._example = _example; 163 | } 164 | 165 | @Override 166 | public Header example(final Object _example) { 167 | setExample(_example); 168 | return this; 169 | } 170 | 171 | @Override 172 | public Map getExamples() { 173 | return _examples; 174 | } 175 | 176 | @Override 177 | public void setExamples(final Map _examples) { 178 | this._examples = _examples; 179 | } 180 | 181 | @Override 182 | public Header examples(final Map _examples) { 183 | setExamples(_examples); 184 | return this; 185 | } 186 | 187 | @Override 188 | public Header addExample(final String key, final Example _examples) { 189 | if (_examples == null) { 190 | return this; 191 | } 192 | (this._examples = this._examples == null ? new LinkedHashMap<>() : this._examples).put(key, _examples); 193 | return this; 194 | } 195 | 196 | @Override 197 | public Boolean getExplode() { 198 | return _explode; 199 | } 200 | 201 | @Override 202 | public void setExplode(final Boolean _explode) { 203 | this._explode = _explode; 204 | } 205 | 206 | @Override 207 | public Header explode(final Boolean _explode) { 208 | setExplode(_explode); 209 | return this; 210 | } 211 | 212 | @Override 213 | @JsonbProperty("$ref") 214 | public String getRef() { 215 | return _ref; 216 | } 217 | 218 | @Override 219 | @JsonbProperty("$ref") 220 | public void setRef(final String _ref) { 221 | this._ref = _ref.startsWith("#") ? _ref : ("#/components/headers/" + _ref); 222 | } 223 | 224 | @Override 225 | public Header ref(final String _ref) { 226 | setRef(_ref); 227 | return this; 228 | } 229 | 230 | @Override 231 | public Boolean getRequired() { 232 | return _required; 233 | } 234 | 235 | @Override 236 | public void setRequired(final Boolean _required) { 237 | this._required = _required; 238 | } 239 | 240 | @Override 241 | public Header required(final Boolean _required) { 242 | setRequired(_required); 243 | return this; 244 | } 245 | 246 | @Override 247 | public Schema getSchema() { 248 | return _schema; 249 | } 250 | 251 | @Override 252 | public void setSchema(final Schema _schema) { 253 | this._schema = _schema; 254 | } 255 | 256 | @Override 257 | public Header schema(final Schema _schema) { 258 | setSchema(_schema); 259 | return this; 260 | } 261 | 262 | @Override 263 | @JsonbTypeAdapter(Serializers.HeaderStyleSerializer.class) 264 | public Style getStyle() { 265 | return _style; 266 | } 267 | 268 | @Override 269 | @JsonbTypeAdapter(Serializers.HeaderStyleSerializer.class) 270 | public void setStyle(final Style _style) { 271 | this._style = _style; 272 | } 273 | 274 | @Override 275 | public Header style(final Style _style) { 276 | setStyle(_style); 277 | return this; 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/loader/ApiBindings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.geronimo.microprofile.openapi.impl.loader; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.apache.geronimo.microprofile.openapi.impl.model.APIResponseImpl; 23 | import org.apache.geronimo.microprofile.openapi.impl.model.APIResponsesImpl; 24 | import org.apache.geronimo.microprofile.openapi.impl.model.CallbackImpl; 25 | import org.apache.geronimo.microprofile.openapi.impl.model.ComponentsImpl; 26 | import org.apache.geronimo.microprofile.openapi.impl.model.ContactImpl; 27 | import org.apache.geronimo.microprofile.openapi.impl.model.ContentImpl; 28 | import org.apache.geronimo.microprofile.openapi.impl.model.DiscriminatorImpl; 29 | import org.apache.geronimo.microprofile.openapi.impl.model.EncodingImpl; 30 | import org.apache.geronimo.microprofile.openapi.impl.model.ExampleImpl; 31 | import org.apache.geronimo.microprofile.openapi.impl.model.ExtensibleImpl; 32 | import org.apache.geronimo.microprofile.openapi.impl.model.ExternalDocumentationImpl; 33 | import org.apache.geronimo.microprofile.openapi.impl.model.HeaderImpl; 34 | import org.apache.geronimo.microprofile.openapi.impl.model.InfoImpl; 35 | import org.apache.geronimo.microprofile.openapi.impl.model.LicenseImpl; 36 | import org.apache.geronimo.microprofile.openapi.impl.model.LinkImpl; 37 | import org.apache.geronimo.microprofile.openapi.impl.model.MediaTypeImpl; 38 | import org.apache.geronimo.microprofile.openapi.impl.model.OAuthFlowImpl; 39 | import org.apache.geronimo.microprofile.openapi.impl.model.OAuthFlowsImpl; 40 | import org.apache.geronimo.microprofile.openapi.impl.model.OpenAPIImpl; 41 | import org.apache.geronimo.microprofile.openapi.impl.model.OperationImpl; 42 | import org.apache.geronimo.microprofile.openapi.impl.model.ParameterImpl; 43 | import org.apache.geronimo.microprofile.openapi.impl.model.PathItemImpl; 44 | import org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl; 45 | import org.apache.geronimo.microprofile.openapi.impl.model.ReferenceImpl; 46 | import org.apache.geronimo.microprofile.openapi.impl.model.RequestBodyImpl; 47 | import org.apache.geronimo.microprofile.openapi.impl.model.SchemaImpl; 48 | import org.apache.geronimo.microprofile.openapi.impl.model.ScopesImpl; 49 | import org.apache.geronimo.microprofile.openapi.impl.model.SecurityRequirementImpl; 50 | import org.apache.geronimo.microprofile.openapi.impl.model.SecuritySchemeImpl; 51 | import org.apache.geronimo.microprofile.openapi.impl.model.ServerImpl; 52 | import org.apache.geronimo.microprofile.openapi.impl.model.ServerVariableImpl; 53 | import org.apache.geronimo.microprofile.openapi.impl.model.ServerVariablesImpl; 54 | import org.apache.geronimo.microprofile.openapi.impl.model.TagImpl; 55 | import org.apache.geronimo.microprofile.openapi.impl.model.XMLImpl; 56 | import org.eclipse.microprofile.openapi.models.Components; 57 | import org.eclipse.microprofile.openapi.models.Extensible; 58 | import org.eclipse.microprofile.openapi.models.ExternalDocumentation; 59 | import org.eclipse.microprofile.openapi.models.OpenAPI; 60 | import org.eclipse.microprofile.openapi.models.Operation; 61 | import org.eclipse.microprofile.openapi.models.PathItem; 62 | import org.eclipse.microprofile.openapi.models.Paths; 63 | import org.eclipse.microprofile.openapi.models.Reference; 64 | import org.eclipse.microprofile.openapi.models.callbacks.Callback; 65 | import org.eclipse.microprofile.openapi.models.examples.Example; 66 | import org.eclipse.microprofile.openapi.models.headers.Header; 67 | import org.eclipse.microprofile.openapi.models.info.Contact; 68 | import org.eclipse.microprofile.openapi.models.info.Info; 69 | import org.eclipse.microprofile.openapi.models.info.License; 70 | import org.eclipse.microprofile.openapi.models.links.Link; 71 | import org.eclipse.microprofile.openapi.models.media.Content; 72 | import org.eclipse.microprofile.openapi.models.media.Discriminator; 73 | import org.eclipse.microprofile.openapi.models.media.Encoding; 74 | import org.eclipse.microprofile.openapi.models.media.MediaType; 75 | import org.eclipse.microprofile.openapi.models.media.Schema; 76 | import org.eclipse.microprofile.openapi.models.media.XML; 77 | import org.eclipse.microprofile.openapi.models.parameters.Parameter; 78 | import org.eclipse.microprofile.openapi.models.parameters.RequestBody; 79 | import org.eclipse.microprofile.openapi.models.responses.APIResponse; 80 | import org.eclipse.microprofile.openapi.models.responses.APIResponses; 81 | import org.eclipse.microprofile.openapi.models.security.OAuthFlow; 82 | import org.eclipse.microprofile.openapi.models.security.OAuthFlows; 83 | import org.eclipse.microprofile.openapi.models.security.Scopes; 84 | import org.eclipse.microprofile.openapi.models.security.SecurityRequirement; 85 | import org.eclipse.microprofile.openapi.models.security.SecurityScheme; 86 | import org.eclipse.microprofile.openapi.models.servers.Server; 87 | import org.eclipse.microprofile.openapi.models.servers.ServerVariable; 88 | import org.eclipse.microprofile.openapi.models.servers.ServerVariables; 89 | import org.eclipse.microprofile.openapi.models.tags.Tag; 90 | 91 | public class ApiBindings { 92 | private ApiBindings() { 93 | // no-op 94 | } 95 | 96 | public static Map, Class> get() { 97 | final Map, Class> mapping = new HashMap<>(33); 98 | mapping.put(APIResponse.class, APIResponseImpl.class); 99 | mapping.put(APIResponses.class, APIResponsesImpl.class); 100 | mapping.put(Callback.class, CallbackImpl.class); 101 | mapping.put(Components.class, ComponentsImpl.class); 102 | mapping.put(Contact.class, ContactImpl.class); 103 | mapping.put(Content.class, ContentImpl.class); 104 | mapping.put(Discriminator.class, DiscriminatorImpl.class); 105 | mapping.put(Encoding.class, EncodingImpl.class); 106 | mapping.put(Example.class, ExampleImpl.class); 107 | mapping.put(Extensible.class, ExtensibleImpl.class); 108 | mapping.put(ExternalDocumentation.class, ExternalDocumentationImpl.class); 109 | mapping.put(Header.class, HeaderImpl.class); 110 | mapping.put(Info.class, InfoImpl.class); 111 | mapping.put(License.class, LicenseImpl.class); 112 | mapping.put(Link.class, LinkImpl.class); 113 | mapping.put(MediaType.class, MediaTypeImpl.class); 114 | mapping.put(OAuthFlow.class, OAuthFlowImpl.class); 115 | mapping.put(OAuthFlows.class, OAuthFlowsImpl.class); 116 | mapping.put(OpenAPI.class, OpenAPIImpl.class); 117 | mapping.put(Operation.class, OperationImpl.class); 118 | mapping.put(Parameter.class, ParameterImpl.class); 119 | mapping.put(PathItem.class, PathItemImpl.class); 120 | mapping.put(Paths.class, PathsImpl.class); 121 | mapping.put(Reference.class, ReferenceImpl.class); 122 | mapping.put(RequestBody.class, RequestBodyImpl.class); 123 | mapping.put(Schema.class, SchemaImpl.class); 124 | mapping.put(Scopes.class, ScopesImpl.class); 125 | mapping.put(SecurityRequirement.class, SecurityRequirementImpl.class); 126 | mapping.put(SecurityScheme.class, SecuritySchemeImpl.class); 127 | mapping.put(Server.class, ServerImpl.class); 128 | mapping.put(ServerVariable.class, ServerVariableImpl.class); 129 | mapping.put(ServerVariables.class, ServerVariablesImpl.class); 130 | mapping.put(Tag.class, TagImpl.class); 131 | mapping.put(XML.class, XMLImpl.class); 132 | return mapping; 133 | } 134 | } 135 | --------------------------------------------------------------------------------