generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OpenAPI Generator] Enable allow-list for API and Model classes #530
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8d6f2c9
Initial
newtork 4399343
Update names
a-d 1bbc455
Merge remote-tracking branch 'origin/main' into openapi/allowlist-api…
a-d 36955cf
Format
a-d f85e2e8
Add test; Minor syntax improvement
a-d e5014e8
Merge remote-tracking branch 'origin/main' into openapi/allowlist-api…
a-d 77a74a5
Update implementation
a-d a78a10e
Format test setup
a-d 568b31d
Update datamodel/openapi/openapi-generator/src/test/resources/DataMod…
newtork fea0825
Format test setup
a-d 69dda79
Merge remote-tracking branch 'origin/openapi/allowlist-apis-and-model…
a-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...src/test/resources/DataModelGeneratorIntegrationTest/generate-models/input/sodastore.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Soda Store API | ||
version: 1.0.0 | ||
description: API for managing sodas in a soda store | ||
paths: | ||
/sodas: | ||
get: | ||
summary: Get a list of all sodas | ||
operationId: getSodas | ||
responses: | ||
'200': | ||
description: A list of sodas | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/OneOf' | ||
components: | ||
schemas: | ||
ShouldNotBeGenerated: | ||
oneOf: | ||
- $ref: '#/components/schemas/Cola' | ||
- $ref: '#/components/schemas/Fanta' | ||
discriminator: | ||
propertyName: sodaType | ||
mapping: | ||
Cola: '#/components/schemas/Cola' | ||
Fanta: '#/components/schemas/Fanta' | ||
OneOfWithDiscriminator: | ||
oneOf: | ||
- $ref: '#/components/schemas/Cola' | ||
- $ref: '#/components/schemas/Fanta' | ||
discriminator: | ||
propertyName: sodaType | ||
OneOf: | ||
oneOf: | ||
- $ref: '#/components/schemas/Cola' | ||
- $ref: '#/components/schemas/Fanta' | ||
AnyOf: | ||
anyOf: | ||
- $ref: '#/components/schemas/Cola' | ||
- $ref: '#/components/schemas/Fanta' | ||
AllOf: | ||
allOf: | ||
- $ref: '#/components/schemas/Cola' | ||
- $ref: '#/components/schemas/Fanta' | ||
Cola: | ||
type: object | ||
properties: | ||
sodaType: | ||
type: string | ||
Fanta: | ||
type: object | ||
properties: | ||
sodaType: | ||
type: string |
158 changes: 158 additions & 0 deletions
158
...rc/test/resources/DataModelGeneratorIntegrationTest/generate-models/output/test/Cola.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. | ||
*/ | ||
|
||
/* | ||
* Soda Store API | ||
* API for managing sodas in a soda store | ||
* | ||
* The version of the OpenAPI document: 1.0.0 | ||
* | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package test; | ||
|
||
import java.util.Objects; | ||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
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.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Cola | ||
*/ | ||
// CHECKSTYLE:OFF | ||
public class Cola | ||
// CHECKSTYLE:ON | ||
{ | ||
@JsonProperty("sodaType") | ||
private String sodaType; | ||
|
||
@JsonAnySetter | ||
@JsonAnyGetter | ||
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>(); | ||
|
||
/** | ||
* Set the sodaType of this {@link Cola} instance and return the same instance. | ||
* | ||
* @param sodaType The sodaType of this {@link Cola} | ||
* @return The same instance of this {@link Cola} class | ||
*/ | ||
@Nonnull public Cola sodaType( @Nullable final String sodaType) { | ||
this.sodaType = sodaType; | ||
return this; | ||
} | ||
|
||
/** | ||
* Get sodaType | ||
* @return sodaType The sodaType of this {@link Cola} instance. | ||
*/ | ||
@Nonnull | ||
public String getSodaType() { | ||
return sodaType; | ||
} | ||
|
||
/** | ||
* Set the sodaType of this {@link Cola} instance. | ||
* | ||
* @param sodaType The sodaType of this {@link Cola} | ||
*/ | ||
public void setSodaType( @Nullable final String sodaType) { | ||
this.sodaType = sodaType; | ||
} | ||
|
||
/** | ||
* Get the names of the unrecognizable properties of the {@link Cola}. | ||
* @return The set of properties names | ||
*/ | ||
@JsonIgnore | ||
@Nonnull | ||
public Set<String> getCustomFieldNames() { | ||
return cloudSdkCustomFields.keySet(); | ||
} | ||
|
||
/** | ||
* Get the value of an unrecognizable property of this {@link Cola} instance. | ||
* @param name The name of the property | ||
* @return The value of the property | ||
* @throws NoSuchElementException If no property with the given name could be found. | ||
*/ | ||
@Nullable | ||
public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { | ||
if( !cloudSdkCustomFields.containsKey(name) ) { | ||
throw new NoSuchElementException("Cola has no field with name '" + name + "'."); | ||
} | ||
return cloudSdkCustomFields.get(name); | ||
} | ||
|
||
/** | ||
* Set an unrecognizable property of this {@link Cola} instance. If the map previously contained a mapping | ||
* for the key, the old value is replaced by the specified value. | ||
* @param customFieldName The name of the property | ||
* @param customFieldValue The value of the property | ||
*/ | ||
@JsonIgnore | ||
public void setCustomField( @Nonnull String customFieldName, @Nullable Object customFieldValue ) | ||
{ | ||
cloudSdkCustomFields.put(customFieldName, customFieldValue); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(@Nullable final java.lang.Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final Cola cola = (Cola) o; | ||
return Objects.equals(this.cloudSdkCustomFields, cola.cloudSdkCustomFields) && | ||
Objects.equals(this.sodaType, cola.sodaType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(sodaType, cloudSdkCustomFields); | ||
} | ||
|
||
@Override | ||
@Nonnull public String toString() { | ||
final StringBuilder sb = new StringBuilder(); | ||
sb.append("class Cola {\n"); | ||
sb.append(" sodaType: ").append(toIndentedString(sodaType)).append("\n"); | ||
cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).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(final java.lang.Object o) { | ||
if (o == null) { | ||
return "null"; | ||
} | ||
return o.toString().replace("\n", "\n "); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) since there is only one API, this only tests that
NotExist
doesn't cause the generation to fail..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the implication of this statement