Skip to content

Commit

Permalink
[core] cleanup: remove OpenAPI parameter from CodegenConfig methods (#…
Browse files Browse the repository at this point in the history
…1953)

* Add OpenAPI parameter to DefaultCodegen#toDefaultValue(..)

* Remove CodegenConfig#fromOperation()

* Remove allDefinitions parameter from fromModel(..)

* Remove definitions parameter from CodegenConfig#fromOperation(..)

* remove schemas parameter from DefaultCodegen#fromRequestBody(..)

* remove schemas parameter from DefaultCodegen#fromCallback(..)

* Remove openAPI parameter from CodegenConfig#fromModel(..)

* Remove openAPI parameter from CodegenConfig#fromOperation(..)

* Remove openAPI parameter from DefaultCodegen#fromProperty(..)

* Remove openAPI parameter from DefaultCodegen#fromParameter(..)

* Remove OpenAPI parameter from several methods

* Use ModelUtils.getReferencedParameter(..)

* Remove unused variable

* Remove openAPI parameter from DefaultCodegen#fromResponse(..)

* Remove openAPI parameter from DefaultCodegen#addHeaders(..)

* Remove from addConsumesInfo(..)/addProducesInfo(..)

* Improve test: add property to prevent Pet from being a free-form object

* remove globalSchemas Map<String, Schema>

* remove deprecated method: postProcessOperations()

* Remove 'Map<String, Schema> allSchemas' from addProperties(..)

* Remove 'Map<String, Schema> allDefinitions' from createDiscriminator(..)

* Remove 'Map<String, Schema> allSchemas' from unaliasPropertySchema(..)

* Rename globalOpenAPI to openAPI

* Update documentation

* Run “Optimize import” in IntelliJ IDEA
  • Loading branch information
jmini authored and wing328 committed Jan 28, 2019
1 parent 6f16b45 commit 046db19
Show file tree
Hide file tree
Showing 243 changed files with 1,369 additions and 2,122 deletions.
18 changes: 18 additions & 0 deletions docs/migration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ The option is replaced with `-g` (`--generator-name`).
* `-g` allows the same values as `-l`
* See `list` command for the list of generator name

==== Access OpenAPI instance as member and not as parameter

If you are creating or extending a generator (programmatically), you might have use one of the following parameters: `OpenAPI openAPI` or `Map<String, Schema> allDefinitions` or `Map<String, Schema> allSchemas`. Example methods:

* `CodegenConfig#fromOperation(String, String, Operation, Map<String, Schema>, OpenAPI)`
* `CodegenConfig#fromModel(String, Schema, Map<String, Schema>)`
* `DefaultCodegen#fromResponse(OpenAPI, String, ApiResponse)`
* `DefaultCodegen#DefaultCodegen.fromRequestBody(RequestBody, Map<String, Schema>, Set<String>, String)`
* `DefaultCodegen#createDiscriminator(String, Schema, Map<String, Schema>)`
* ...

The parameters (`openAPI`, `allDefinitions`, `allSchemas` ...) are now removed from the methods.

To access the current OpenAPI instance, if you are extending `DefaultCodegen` you can use the protected `openAPI` member.

If you are creating your own generator by implementing `CodegenConfig`, then the setter `CodegenConfig.setOpenAPI(OpenAPI)` will be called.
You can keep a reference on the `OpenAPI` instance.

=== From 3.1.x to 3.2.0

Version `3.2.0` is a minor version of OpenAPI-Generator, in comparison to `3.1.x` it contains some breaking changes, but with the possibility to fallback to the old behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Iterator;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConfigParser {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigParser.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@

package org.openapitools.codegen;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.regex.Pattern;

public abstract class AbstractGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openapitools.codegen;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.v3.parser.util.SchemaTypeUtil;

import java.util.LinkedHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.AuthorizationValue;
import java.util.List;
import org.openapitools.codegen.auth.AuthParser;

import java.util.List;

public class ClientOptInput {
private CodegenConfig config;
private ClientOpts opts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.openapitools.codegen;

import org.openapitools.codegen.auth.AuthMethod;

import java.util.HashMap;
import java.util.Map;

import org.openapitools.codegen.auth.AuthMethod;

public class ClientOpts {
protected String uri;
protected String target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openapitools.codegen;

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.media.Schema;
Expand All @@ -27,7 +26,6 @@
import io.swagger.v3.oas.models.servers.ServerVariable;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -111,11 +109,9 @@ public interface CodegenConfig {

void setOutputDir(String dir);

CodegenModel fromModel(String name, Schema schema, Map<String, Schema> allDefinitions);

CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Schema> definitions, OpenAPI openAPI);
CodegenModel fromModel(String name, Schema schema);

CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Schema> definitions);
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation);

List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> schemas);

Expand Down Expand Up @@ -179,14 +175,6 @@ public interface CodegenConfig {

Map<String, Object> postProcessModels(Map<String, Object> objs);

/**
* @deprecated use {@link #postProcessOperationsWithModels(Map, List)} instead. This method will be removed
* @param objs the objects map that will be passed to the templating engine
* @return the the objects map instance.
*/
@Deprecated
Map<String, Object> postProcessOperations(Map<String, Object> objs);

Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels);

Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs);
Expand Down Expand Up @@ -266,9 +254,10 @@ public interface CodegenConfig {

void setEnablePostProcessFile(boolean isEnablePostProcessFile);

// set OpenAPI and schemas
void setGlobalOpenAPI(OpenAPI openAPI);

void setGlobalSchemas(OpenAPI openAPI);
/**
* Set the OpenAPI instance. This method needs to be called right after the instantiation of the Codegen class.
* @param openAPI specification being generated
*/
void setOpenAPI(OpenAPI openAPI);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openapitools.codegen;

import static java.util.ServiceLoader.load;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import static java.util.ServiceLoader.load;

public class CodegenConfigLoader {
/**
* Tries to load config class with SPI first, then with class name directly from classpath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.*;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class CodegenDiscriminator {
private String propertyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

package org.openapitools.codegen;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.models.ExternalDocumentation;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;

@JsonIgnoreProperties({"parentModel", "interfaceModels"})
public class CodegenModel {
public String parent, parentSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.tags.Tag;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class CodegenOperation {
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openapitools.codegen;

import io.swagger.v3.oas.models.security.Scopes;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down
Loading

0 comments on commit 046db19

Please sign in to comment.