Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v2 generate component headers #100

Merged
merged 31 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
56bdcbf
Adds CodegenHeader
spacether Dec 4, 2022
ce1aca6
Updates fromParameter
spacether Dec 4, 2022
3001506
Moves setContent into fromParameter, simplifies fromParameter
spacether Dec 4, 2022
21abe0e
Refactors fromParameter property assignment into helper method
spacether Dec 4, 2022
159a910
Adds missing methods to generate header components
spacether Dec 4, 2022
52fc955
Updates param and header code to set correct style, updated header te…
spacether Dec 4, 2022
c18c460
Adds OpenapiComponent interface
spacether Dec 4, 2022
da7dfeb
Fixes request body component docs to use modulePath
spacether Dec 4, 2022
98a1075
Uses modulePath in response docs
spacether Dec 4, 2022
9fb5cdf
Has model docs use modulePath
spacether Dec 4, 2022
c3b4298
Improves fromHeader usage
spacether Dec 4, 2022
c8ee666
Fixes iterating over response headers
spacether Dec 4, 2022
a438904
Refactors CodegenParameter toString, fixes header style
spacether Dec 5, 2022
184fbf0
Regenerate sample, refed headers should not be generated inline
spacether Dec 5, 2022
1b452d7
Adds refed headers in path response header and component response header
spacether Dec 5, 2022
68fa610
Adds imports for refed headers
spacether Dec 5, 2022
4306955
Adds java code to generate header docs, CodegenResponse.responseHeade…
spacether Dec 6, 2022
214a834
CodegenOperation.bodyParam changed to requestBody
spacether Dec 6, 2022
f002873
Samples regenerated
spacether Dec 6, 2022
e6f0e17
Header doc files generated
spacether Dec 6, 2022
d348f37
Fixes link to component headers
spacether Dec 6, 2022
5eeedfd
Removes header details when there is a ref link
spacether Dec 6, 2022
552f6c4
Fixes refed header links
spacether Dec 6, 2022
a47755f
Corrects header doc link
spacether Dec 6, 2022
af8bb2e
Fixes response component link to header in docs
spacether Dec 6, 2022
680ee81
Samples regenerated
spacether Dec 6, 2022
8fb659f
Adds Int32JsonContentTypeHeader
spacether Dec 6, 2022
bf02623
Fixes one doc link to the new header
spacether Dec 6, 2022
14d952b
Fixes last remaining doc link to the header doc
spacether Dec 6, 2022
3eeb6b6
Samples regenerated
spacether Dec 6, 2022
5d1a27f
Fixes Java tests
spacether Dec 6, 2022
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
Expand Up @@ -20,6 +20,7 @@
import com.samskivert.mustache.Mustache.Compiler;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
Expand Down Expand Up @@ -83,6 +84,10 @@ public interface CodegenConfig {

String requestBodyDocFileFolder();

String headerFileFolder();

String headerDocFileFolder();

String modelPackage();

String packageName();
Expand Down Expand Up @@ -171,6 +176,10 @@ public interface CodegenConfig {

Map<String, String> requestBodyDocTemplateFiles();

Map<String, String> headerTemplateFiles();

Map<String, String> headerDocTemplateFiles();

Map<String, String> pathEndpointTemplateFiles();

Set<String> pathEndpointTestTemplateFiles();
Expand Down Expand Up @@ -231,6 +240,10 @@ public interface CodegenConfig {

String toResponseDocFilename(String componentName);

String toHeaderDocFilename(String componentName);

String toHeaderFilename(String componentName);

String toPathFileName(String path);

String toParameterFileName(String baseName);
Expand Down Expand Up @@ -388,4 +401,6 @@ public interface CodegenConfig {
String getBodyParameterName(CodegenOperation co);

CodegenResponse fromResponse(ApiResponse response, String sourceJsonPath);

CodegenHeader fromHeader(Header parameter, String sourceJsonPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class CodegenConstants {
public static final String REQUEST_BODY_DOCS = "requestBodyDocs";

public static final String RESPONSES = "responses";

public static final String HEADERS = "headers";
public static final String HEADER_DOCS = "headerDocs";
public static final String SUPPORTING_FILES = "supportingFiles";
public static final String MODEL_TESTS = "modelTests";
public static final String MODEL_DOCS = "modelDocs";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.openapitools.codegen;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class CodegenEncoding {
private String contentType;
private List<CodegenParameter> headers;
private Map<String, CodegenHeader> headers;
private String style;
private boolean explode;
private boolean allowReserved;

public CodegenEncoding(String contentType, List<CodegenParameter> headers, String style, boolean explode, boolean allowReserved) {
public CodegenEncoding(String contentType, Map<String, CodegenHeader> headers, String style, boolean explode, boolean allowReserved) {
this.contentType = contentType;
this.headers = headers;
this.style = style;
Expand All @@ -22,7 +23,7 @@ public String getContentType() {
return contentType;
}

public List<CodegenParameter> getHeaders() {
public Map<String, CodegenHeader> getHeaders() {
return headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.codegen;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
* Describes a single operation parameter in the OAS specification.
* A unique parameter is defined by a combination of a name and location.
* Parameters may be located in a path, query, header or cookie.
*/
public class CodegenHeader implements OpenapiComponent {
public boolean isExplode;
public String paramName,
description, unescapedDescription, style;

public String nameInLowerCase; // property name in lower case
public String example; // example value (x-example)
public String jsonSchema;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
public boolean isDeprecated;
protected CodegenProperty schema;
/**
* Determines whether this parameter is mandatory. If the parameter is in "path",
* this property is required and its value MUST be true. Otherwise, the property
* MAY be included and its default value is false.
*/
public boolean required;
protected boolean hasMultipleTypes = false;
protected LinkedHashMap<String, CodegenMediaType> content;
protected String ref;
protected String refModule;

public Set<String> imports = new HashSet<String>();

protected String modulePath;

public CodegenHeader copy() {
CodegenHeader output = new CodegenHeader();
output.paramName = this.paramName;
output.description = this.description;
output.unescapedDescription = this.unescapedDescription;
output.required = this.required;
output.jsonSchema = this.jsonSchema;
output.example = this.example;

if (this.content != null) {
output.setContent(this.content);
}
if (this.schema != null) {
output.setSchema(this.schema);
}
if (this.vendorExtensions != null) {
output.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
}
if (this.ref != null) {
output.setRef(this.ref);
}
if (this.refModule != null) {
output.setRefModule(this.refModule);
}
if (this.imports != null) {
output.imports = imports;
}
if (this.modulePath != null) {
output.modulePath = modulePath;
}
output.isDeprecated = this.isDeprecated;
output.isExplode = this.isExplode;
output.style = this.style;

return output;
}

public String getModulePath() {
return modulePath;
}

public void setModulePath(String modulePath) {
this.modulePath = modulePath;
}

@Override
public int hashCode() {
return Objects.hash(isExplode, paramName, description, unescapedDescription, style, example, jsonSchema, vendorExtensions, isDeprecated, required, hasMultipleTypes, schema, content, ref, refModule, imports, modulePath);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CodegenHeader)) return false;
CodegenHeader that = (CodegenHeader) o;
return isExplode == that.isExplode &&
isDeprecated == that.isDeprecated &&
required == that.required &&
Objects.equals(modulePath, that.modulePath) &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(imports, that.imports) &&
Objects.equals(refModule, that.getRefModule()) &&
Objects.equals(content, that.getContent()) &&
Objects.equals(schema, that.getSchema()) &&
Objects.equals(paramName, that.paramName) &&
Objects.equals(description, that.description) &&
Objects.equals(unescapedDescription, that.unescapedDescription) &&
Objects.equals(style, that.style) &&
Objects.equals(example, that.example) &&
Objects.equals(jsonSchema, that.jsonSchema) &&
Objects.equals(vendorExtensions, that.vendorExtensions);
}

protected void addInstanceInfo(StringBuilder sb) {
sb.append(", isExplode=").append(isExplode);
sb.append(", paramName='").append(paramName).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", unescapedDescription='").append(unescapedDescription).append('\'');
sb.append(", style='").append(style).append('\'');
sb.append(", example='").append(example).append('\'');
sb.append(", jsonSchema='").append(jsonSchema).append('\'');
sb.append(", vendorExtensions=").append(vendorExtensions);
sb.append(", isDeprecated=").append(isDeprecated);
sb.append(", required=").append(required);
sb.append(", hasMultipleTypes=").append(hasMultipleTypes);
sb.append(", schema=").append(schema);
sb.append(", content=").append(content);
sb.append(", ref=").append(ref);
sb.append(", refModule=").append(refModule);
sb.append(", imports=").append(imports);
sb.append(", modulePath=").append(modulePath);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CodegenHeader{");
addInstanceInfo(sb);
sb.append('}');
return sb.toString();
}

public CodegenProperty getSchema() {
return schema;
}

public void setSchema(CodegenProperty schema) {
this.schema = schema;
}

public LinkedHashMap<String, CodegenMediaType> getContent() {
return content;
}

public void setContent(LinkedHashMap<String, CodegenMediaType> content) {
this.content = content;
}


public String getRef() { return ref; }

public void setRef(String ref) { this.ref=ref; }

public String getRefModule() { return refModule; }

public void setRefModule(String refModule) { this.refModule=refModule; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* CodegenModel represents a schema object in a OpenAPI document.
*/
@JsonIgnoreProperties({"parentModel", "interfaceModels"})
public class CodegenModel implements JsonSchema {
public class CodegenModel implements JsonSchema, OpenapiComponent {
// The parent model name from the schemas. The parent is determined by inspecting the allOf, anyOf and
// oneOf attributes in the OAS. First codegen inspects 'allOf', then 'anyOf', then 'oneOf'.
// If there are multiple object references in the attribute ('allOf', 'anyOf', 'oneOf'), and one of the
Expand Down Expand Up @@ -117,6 +117,7 @@ public class CodegenModel implements JsonSchema {
private String format;
private LinkedHashMap<String, List<String>> dependentRequired;
private CodegenProperty contains;
private String modulePath;

/**
* The type of the value for the additionalProperties keyword in the OAS document.
Expand Down Expand Up @@ -175,6 +176,14 @@ public class CodegenModel implements JsonSchema {
private String ref;
private String refModule;

public String getModulePath() {
return modulePath;
}

public void setModulePath(String modulePath) {
this.modulePath = modulePath;
}

public String getAdditionalPropertiesType() {
return additionalPropertiesType;
}
Expand Down Expand Up @@ -1023,6 +1032,7 @@ public boolean equals(Object o) {
getUniqueItems() == that.getUniqueItems() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
Objects.equals(modulePath, that.modulePath) &&
Objects.equals(contains, that.getContains()) &&
Objects.equals(dependentRequired, that.getDependentRequired()) &&
Objects.equals(format, that.getFormat()) &&
Expand Down Expand Up @@ -1104,7 +1114,7 @@ hasChildren, isMap, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), g
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping,
isAnyType, getComposedSchemas(), hasMultipleTypes, isDecimal, isUuid, requiredVarsMap, ref,
uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
format, dependentRequired, contains, refModule);
format, dependentRequired, contains, refModule, modulePath);
}

@Override
Expand Down Expand Up @@ -1211,6 +1221,7 @@ public String toString() {
sb.append(", format=").append(format);
sb.append(", dependentRequired=").append(dependentRequired);
sb.append(", contains=").append(contains);
sb.append(", modulePath").append(modulePath);
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CodegenOperation {
summary, unescapedNotes, notes, baseName;
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
public List<CodegenServer> servers = new ArrayList<CodegenServer>();
public CodegenParameter bodyParam;
public CodegenParameter requestBody;
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> pathParams = new ArrayList<CodegenParameter>();
Expand Down Expand Up @@ -200,10 +200,10 @@ public boolean getAllResponsesAreErrors() {
*/
public Map<String, CodegenOperation> getContentTypeToOperation() {
LinkedHashMap<String, CodegenOperation> contentTypeToOperation = new LinkedHashMap<>();
if (bodyParam == null) {
if (requestBody == null) {
return null;
}
LinkedHashMap<String, CodegenMediaType> content = bodyParam.getContent();
LinkedHashMap<String, CodegenMediaType> content = requestBody.getContent();
for (String contentType: content.keySet()) {
contentTypeToOperation.put(contentType, this);
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public String toString() {
sb.append(", produces=").append(produces);
sb.append(", prioritizedContentTypes=").append(prioritizedContentTypes);
sb.append(", servers=").append(servers);
sb.append(", bodyParam=").append(bodyParam);
sb.append(", requestBody=").append(requestBody);
sb.append(", allParams=").append(allParams);
sb.append(", bodyParams=").append(bodyParams);
sb.append(", pathParams=").append(pathParams);
Expand Down Expand Up @@ -401,7 +401,7 @@ public boolean equals(Object o) {
Objects.equals(produces, that.produces) &&
Objects.equals(prioritizedContentTypes, that.prioritizedContentTypes) &&
Objects.equals(servers, that.servers) &&
Objects.equals(bodyParam, that.bodyParam) &&
Objects.equals(requestBody, that.requestBody) &&
Objects.equals(allParams, that.allParams) &&
Objects.equals(bodyParams, that.bodyParams) &&
Objects.equals(pathParams, that.pathParams) &&
Expand Down Expand Up @@ -439,7 +439,7 @@ public int hashCode() {
hasDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, httpMethod,
summary, unescapedNotes, notes, baseName, defaultResponse,
consumes, produces, prioritizedContentTypes, servers, bodyParam, allParams, bodyParams,
consumes, produces, prioritizedContentTypes, servers, requestBody, allParams, bodyParams,
pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, optionalParams,
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase,
Expand Down
Loading