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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{>additionalOneOfTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
{{#vendorExtensions.x-class-extra-annotation}}
{{{vendorExtensions.x-class-extra-annotation}}}
{{/vendorExtensions.x-class-extra-annotation}}
public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}}{{>permits}}{
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}}
{{/interfaceModels}}
})
{{/useDeductionForOneOfInterfaces}}
{{/useDeductionForOneOfInterfaces}}{{#vendorExtensions.x-class-extra-annotation}}{{{vendorExtensions.x-class-extra-annotation}}}
{{/vendorExtensions.x-class-extra-annotation}}
{{/discriminator}}
{{>generatedAnnotation}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3924,4 +3924,21 @@ public void oneOfWithInnerModelTest() {
}
assertTrue(speciesSeen);
}
}

@Test
public void testOneOfClassWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT);
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isNormalClass()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}

@Test
public void testOneOfInterfaceWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT,
Map.of(USE_ONE_OF_INTERFACES, "true"));
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isInterface()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5730,4 +5730,12 @@ public void testHasRestControllerDoesNotHaveController_issue21156() throws IOExc
javaFileAssert
.hasImports("java.util.concurrent.atomic.AtomicInteger");
}

@Test
public void testOneOfInterfaceWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", SPRING_BOOT);
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isInterface()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: 3.0.1
info:
title: fruity
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: desc
content:
application/json:
schema:
$ref: '#/components/schemas/fruit'
components:
schemas:
fruit:
title: fruit
x-class-extra-annotation: '@SuppressWarnings("unchecked")'
properties:
color:
type: string
oneOf:
- $ref: '#/components/schemas/apple'
- $ref: '#/components/schemas/banana'
- $ref: '#/components/schemas/orange'
apple:
title: apple
type: object
properties:
kind:
type: string
banana:
title: banana
type: object
properties:
count:
type: number
orange:
title: orange
type: object
properties:
sweet:
type: boolean
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ Class | Method | HTTP request | Description
## Documentation for Models

- [Addressable](docs/Addressable.md)
- [Animal](docs/Animal.md)
- [Apple](docs/Apple.md)
- [Banana](docs/Banana.md)
- [Bar](docs/Bar.md)
- [BarCreate](docs/BarCreate.md)
- [BarRef](docs/BarRef.md)
- [BarRefOrValue](docs/BarRefOrValue.md)
- [Cat](docs/Cat.md)
- [Dog](docs/Dog.md)
- [Entity](docs/Entity.md)
- [EntityRef](docs/EntityRef.md)
- [Extensible](docs/Extensible.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,19 @@ components:
required:
- length
type: object
Animal:
oneOf:
- $ref: "#/components/schemas/Dog"
- $ref: "#/components/schemas/Cat"
x-one-of-name: Animal
Cat:
properties:
declawed:
type: boolean
type: object
Dog:
properties:
bark:
type: boolean
type: object

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


# Interface Animal

## Implementing Classes

* Cat
* Dog


17 changes: 17 additions & 0 deletions samples/client/others/java/webclient-sealedInterface/docs/Cat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


# Cat


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**declawed** | **Boolean** | | [optional] |


## Implemented Interfaces

* Animal


17 changes: 17 additions & 0 deletions samples/client/others/java/webclient-sealedInterface/docs/Dog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


# Dog


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**bark** | **Boolean** | | [optional] |


## Implemented Interfaces

* Animal


Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* ByRefOrValue
* This tests for a oneOf interface representation
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package org.openapitools.client.model;

import java.util.Objects;
import java.util.Arrays;
import java.util.Locale;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.Cat;
import org.openapitools.client.model.Dog;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.16.0-SNAPSHOT")
@JsonIgnoreProperties(
value = "", // ignore manually set , it will be automatically generated by Jackson during serialization
allowSetters = true // allows the to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "", visible = true)

public sealed interface Animal permits Dog, Cat {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* ByRefOrValue
* This tests for a oneOf interface representation
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package org.openapitools.client.model;

import java.util.Objects;
import java.util.Arrays;
import java.util.Locale;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

/**
* Cat
*/
@JsonPropertyOrder({
Cat.JSON_PROPERTY_DECLAWED
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.16.0-SNAPSHOT")
public final class Cat implements Animal {
public static final String JSON_PROPERTY_DECLAWED = "declawed";
@javax.annotation.Nullable
private Boolean declawed;

public Cat() {
}

public Cat declawed(@javax.annotation.Nullable Boolean declawed) {

this.declawed = declawed;
return this;
}

/**
* Get declawed
* @return declawed
*/
@javax.annotation.Nullable
@JsonProperty(value = JSON_PROPERTY_DECLAWED, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public Boolean getDeclawed() {
return declawed;
}


@JsonProperty(value = JSON_PROPERTY_DECLAWED, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setDeclawed(@javax.annotation.Nullable Boolean declawed) {
this.declawed = declawed;
}


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Cat cat = (Cat) o;
return Objects.equals(this.declawed, cat.declawed);
}

@Override
public int hashCode() {
return Objects.hash(declawed);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Cat {\n");
sb.append(" declawed: ").append(toIndentedString(declawed)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Loading
Loading