Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !700

Add an option to skip "form" model generation

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged William Cheng requested to merge generate_all_model into master 6 years ago
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 27

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

To fix https://github.com/OpenAPITools/openapi-generator/issues/405

To enable skipping "form" model generation, please use the following as stated in the updated doc:

java -DskipFormModel=true
Compare
  • master (base)

and
  • latest version
    a67312b7
    7 commits, 2 years ago

27 files
+ 3702
- 12

    Preferences

    File browser
    Compare changes
do‎cs‎
customiz‎ation.md‎ +8 -0
modules/…/…/…‎/…/…/…/codegen‎
CodegenCon‎stants.java‎ +1 -0
DefaultGen‎erator.java‎ +12 -3
sam‎ples‎
client/petstore/h‎askell-http-client‎
lib/OpenA‎PIPetstore‎
A‎PI‎
Fak‎e.hs‎ +3 -3
Mode‎l.hs‎ +253 -6
ModelL‎ens.hs‎ +144 -0
te‎sts‎
Instan‎ces.hs‎ +48 -0
Tes‎t.hs‎ +6 -0
openapi3/client/…/p‎hp/OpenAPIClient-php‎
docs/‎Model‎
Bod‎y.md‎ +11 -0
Body‎1.md‎ +11 -0
Body‎2.md‎ +11 -0
Body‎3.md‎ +23 -0
Body‎4.md‎ +11 -0
Body‎5.md‎ +11 -0
lib/‎Model‎
Body‎.php‎ +327 -0
Body‎1.php‎ +327 -0
Body‎2.php‎ +385 -0
Body‎3.php‎ +805 -0
Body‎4.php‎ +333 -0
Body‎5.php‎ +330 -0
test/‎Model‎
Body1T‎est.php‎ +92 -0
Body2T‎est.php‎ +92 -0
Body3T‎est.php‎ +176 -0
Body4T‎est.php‎ +92 -0
Body5T‎est.php‎ +92 -0
BodyTe‎st.php‎ +92 -0
READ‎ME.md‎ +6 -0
docs/customization.md
+ 8
- 0
  • View file @ a67312b7

  • Edit in single-file editor

  • Open in Web IDE


@@ -106,6 +106,14 @@ java -Dapis -DmodelTests=false {opts}
When using selective generation, _only_ the templates needed for the specific generation will be used.
To skip models defined as the form parameters in "requestBody", please use `skipFormModel` (default to false) (this option is introduced at v3.2.2)
```sh
java -DskipFormModel=true
```
This option will be helpful to skip model generation due to the form parameter, which is defined differently in OAS3 as there's no form parameter in OAS3
### Ignore file format
OpenAPI Generator supports a `.openapi-generator-ignore` file, similar to `.gitignore` or `.dockerignore` you're probably already familiar with.
modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
+ 1
- 0
  • View file @ a67312b7

  • Edit in single-file editor

  • Open in Web IDE


@@ -31,6 +31,7 @@ public class CodegenConstants {
public static final String API_TESTS = "apiTests";
public static final String API_DOCS = "apiDocs";
public static final String WITH_XML = "withXml";
public static final String SKIP_FORM_MODEL = "skipFormModel";
/* /end System Properties */
public static final String API_PACKAGE = "apiPackage";
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java
+ 12
- 3
  • View file @ a67312b7

  • Edit in single-file editor

  • Open in Web IDE


@@ -286,7 +286,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
private void generateModelDocumentation(List<File> files, Map<String, Object> models, String modelName) throws IOException {
for (String templateName : config.modelDocTemplateFiles().keySet()) {
String docExtension = config.getDocExtension();
String suffix = docExtension!=null ? docExtension : config.modelDocTemplateFiles().get(templateName);
String suffix = docExtension != null ? docExtension : config.modelDocTemplateFiles().get(templateName);
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(modelName) + suffix;
if (!config.shouldOverwrite(filename)) {
LOGGER.info("Skipped overwriting " + filename);
@@ -382,6 +382,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
} */
});
Boolean skipFormModel = System.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ?
Boolean.valueOf(System.getProperty(CodegenConstants.SKIP_FORM_MODEL)) :
getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, false);
// process models only
for (String name : modelKeys) {
try {
@@ -393,8 +397,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
// don't generate models that are not used as object (e.g. form parameters)
if (unusedModels.contains(name)) {
LOGGER.debug("Model " + name + " not generated since it's marked as unused (due to form parameters)");
continue;
if (Boolean.FALSE.equals(skipFormModel)) {
// if skipFormModel sets to true, still generate the model and log the result
LOGGER.info("Model " + name + " (marked as unused due to form parameters) is generated due to skipFormModel=false (default)");
} else {
LOGGER.info("Model " + name + " not generated since it's marked as unused (due to form parameters) and skipFormModel set to true");
continue;
}
}
Schema schema = schemas.get(name);
samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/API/Fake.hs
+ 3
- 3
  • View file @ a67312b7

  • Edit in single-file editor

  • Open in Web IDE


@@ -73,7 +73,7 @@ fakeOuterBooleanSerialize _ =
data FakeOuterBooleanSerialize
-- | /Body Param/ "body" - Input boolean as post body
instance HasBodyParam FakeOuterBooleanSerialize BodyBool
instance HasBodyParam FakeOuterBooleanSerialize Body8
-- | @application/json@
instance Consumes FakeOuterBooleanSerialize MimeJSON
@@ -123,7 +123,7 @@ fakeOuterNumberSerialize _ =
data FakeOuterNumberSerialize
-- | /Body Param/ "body" - Input number as post body
instance HasBodyParam FakeOuterNumberSerialize Body
instance HasBodyParam FakeOuterNumberSerialize Body6
-- | @application/json@
instance Consumes FakeOuterNumberSerialize MimeJSON
@@ -148,7 +148,7 @@ fakeOuterStringSerialize _ =
data FakeOuterStringSerialize
-- | /Body Param/ "body" - Input string as post body
instance HasBodyParam FakeOuterStringSerialize BodyText
instance HasBodyParam FakeOuterStringSerialize Body7
-- | @application/json@
instance Consumes FakeOuterStringSerialize MimeJSON
samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/Model.hs
+ 253
- 6
  • View file @ a67312b7

  • Edit in single-file editor

  • Open in Web IDE


@@ -72,14 +72,14 @@ newtype AdditionalMetadata = AdditionalMetadata { unAdditionalMetadata :: Text }
-- ** ApiKey
newtype ApiKey = ApiKey { unApiKey :: Text } deriving (P.Eq, P.Show)
-- ** Body
newtype Body = Body { unBody :: Double } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body6
newtype Body6 = Body6 { unBody6 :: Double } deriving (P.Eq, P.Show, A.ToJSON)
-- ** BodyBool
newtype BodyBool = BodyBool { unBodyBool :: Bool } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body7
newtype Body7 = Body7 { unBody7 :: Text } deriving (P.Eq, P.Show, A.ToJSON)
-- ** BodyText
newtype BodyText = BodyText { unBodyText :: Text } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Body8
newtype Body8 = Body8 { unBody8 :: Bool } deriving (P.Eq, P.Show, A.ToJSON)
-- ** Byte
newtype Byte = Byte { unByte :: ByteArray } deriving (P.Eq, P.Show)
@@ -416,6 +416,253 @@ mkArrayTest =
, arrayTestArrayArrayOfModel = Nothing
}
-- ** Body
-- | Body
data Body = Body
{ bodyName :: !(Maybe Text) -- ^ "name" - Updated name of the pet
, bodyStatus :: !(Maybe Text) -- ^ "status" - Updated status of the pet
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body
instance A.FromJSON Body where
parseJSON = A.withObject "Body" $ \o ->
Body
<$> (o .:? "name")
<*> (o .:? "status")
-- | ToJSON Body
instance A.ToJSON Body where
toJSON Body {..} =
_omitNulls
[ "name" .= bodyName
, "status" .= bodyStatus
]
-- | Construct a value of type 'Body' (by applying it's required fields, if any)
mkBody
:: Body
mkBody =
Body
{ bodyName = Nothing
, bodyStatus = Nothing
}
-- ** Body1
-- | Body1
data Body1 = Body1
{ body1AdditionalMetadata :: !(Maybe Text) -- ^ "additionalMetadata" - Additional data to pass to server
, body1File :: !(Maybe FilePath) -- ^ "file" - file to upload
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body1
instance A.FromJSON Body1 where
parseJSON = A.withObject "Body1" $ \o ->
Body1
<$> (o .:? "additionalMetadata")
<*> (o .:? "file")
-- | ToJSON Body1
instance A.ToJSON Body1 where
toJSON Body1 {..} =
_omitNulls
[ "additionalMetadata" .= body1AdditionalMetadata
, "file" .= body1File
]
-- | Construct a value of type 'Body1' (by applying it's required fields, if any)
mkBody1
:: Body1
mkBody1 =
Body1
{ body1AdditionalMetadata = Nothing
, body1File = Nothing
}
-- ** Body2
-- | Body2
data Body2 = Body2
{ body2EnumFormStringArray :: !(Maybe [E'EnumFormStringArray]) -- ^ "enum_form_string_array" - Form parameter enum test (string array)
, body2EnumFormString :: !(Maybe E'EnumFormString) -- ^ "enum_form_string" - Form parameter enum test (string)
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body2
instance A.FromJSON Body2 where
parseJSON = A.withObject "Body2" $ \o ->
Body2
<$> (o .:? "enum_form_string_array")
<*> (o .:? "enum_form_string")
-- | ToJSON Body2
instance A.ToJSON Body2 where
toJSON Body2 {..} =
_omitNulls
[ "enum_form_string_array" .= body2EnumFormStringArray
, "enum_form_string" .= body2EnumFormString
]
-- | Construct a value of type 'Body2' (by applying it's required fields, if any)
mkBody2
:: Body2
mkBody2 =
Body2
{ body2EnumFormStringArray = Nothing
, body2EnumFormString = Nothing
}
-- ** Body3
-- | Body3
data Body3 = Body3
{ body3Integer :: !(Maybe Int) -- ^ "integer" - None
, body3Int32 :: !(Maybe Int) -- ^ "int32" - None
, body3Int64 :: !(Maybe Integer) -- ^ "int64" - None
, body3Number :: !(Double) -- ^ /Required/ "number" - None
, body3Float :: !(Maybe Float) -- ^ "float" - None
, body3Double :: !(Double) -- ^ /Required/ "double" - None
, body3String :: !(Maybe Text) -- ^ "string" - None
, body3PatternWithoutDelimiter :: !(Text) -- ^ /Required/ "pattern_without_delimiter" - None
, body3Byte :: !(ByteArray) -- ^ /Required/ "byte" - None
, body3Binary :: !(Maybe FilePath) -- ^ "binary" - None
, body3Date :: !(Maybe Date) -- ^ "date" - None
, body3DateTime :: !(Maybe DateTime) -- ^ "dateTime" - None
, body3Password :: !(Maybe Text) -- ^ "password" - None
, body3Callback :: !(Maybe Text) -- ^ "callback" - None
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body3
instance A.FromJSON Body3 where
parseJSON = A.withObject "Body3" $ \o ->
Body3
<$> (o .:? "integer")
<*> (o .:? "int32")
<*> (o .:? "int64")
<*> (o .: "number")
<*> (o .:? "float")
<*> (o .: "double")
<*> (o .:? "string")
<*> (o .: "pattern_without_delimiter")
<*> (o .: "byte")
<*> (o .:? "binary")
<*> (o .:? "date")
<*> (o .:? "dateTime")
<*> (o .:? "password")
<*> (o .:? "callback")
-- | ToJSON Body3
instance A.ToJSON Body3 where
toJSON Body3 {..} =
_omitNulls
[ "integer" .= body3Integer
, "int32" .= body3Int32
, "int64" .= body3Int64
, "number" .= body3Number
, "float" .= body3Float
, "double" .= body3Double
, "string" .= body3String
, "pattern_without_delimiter" .= body3PatternWithoutDelimiter
, "byte" .= body3Byte
, "binary" .= body3Binary
, "date" .= body3Date
, "dateTime" .= body3DateTime
, "password" .= body3Password
, "callback" .= body3Callback
]
-- | Construct a value of type 'Body3' (by applying it's required fields, if any)
mkBody3
:: Double -- ^ 'body3Number': None
-> Double -- ^ 'body3Double': None
-> Text -- ^ 'body3PatternWithoutDelimiter': None
-> ByteArray -- ^ 'body3Byte': None
-> Body3
mkBody3 body3Number body3Double body3PatternWithoutDelimiter body3Byte =
Body3
{ body3Integer = Nothing
, body3Int32 = Nothing
, body3Int64 = Nothing
, body3Number
, body3Float = Nothing
, body3Double
, body3String = Nothing
, body3PatternWithoutDelimiter
, body3Byte
, body3Binary = Nothing
, body3Date = Nothing
, body3DateTime = Nothing
, body3Password = Nothing
, body3Callback = Nothing
}
-- ** Body4
-- | Body4
data Body4 = Body4
{ body4Param :: !(Text) -- ^ /Required/ "param" - field1
, body4Param2 :: !(Text) -- ^ /Required/ "param2" - field2
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body4
instance A.FromJSON Body4 where
parseJSON = A.withObject "Body4" $ \o ->
Body4
<$> (o .: "param")
<*> (o .: "param2")
-- | ToJSON Body4
instance A.ToJSON Body4 where
toJSON Body4 {..} =
_omitNulls
[ "param" .= body4Param
, "param2" .= body4Param2
]
-- | Construct a value of type 'Body4' (by applying it's required fields, if any)
mkBody4
:: Text -- ^ 'body4Param': field1
-> Text -- ^ 'body4Param2': field2
-> Body4
mkBody4 body4Param body4Param2 =
Body4
{ body4Param
, body4Param2
}
-- ** Body5
-- | Body5
data Body5 = Body5
{ body5AdditionalMetadata :: !(Maybe Text) -- ^ "additionalMetadata" - Additional data to pass to server
, body5RequiredFile :: !(FilePath) -- ^ /Required/ "requiredFile" - file to upload
} deriving (P.Show, P.Eq, P.Typeable)
-- | FromJSON Body5
instance A.FromJSON Body5 where
parseJSON = A.withObject "Body5" $ \o ->
Body5
<$> (o .:? "additionalMetadata")
<*> (o .: "requiredFile")
-- | ToJSON Body5
instance A.ToJSON Body5 where
toJSON Body5 {..} =
_omitNulls
[ "additionalMetadata" .= body5AdditionalMetadata
, "requiredFile" .= body5RequiredFile
]
-- | Construct a value of type 'Body5' (by applying it's required fields, if any)
mkBody5
:: FilePath -- ^ 'body5RequiredFile': file to upload
-> Body5
mkBody5 body5RequiredFile =
Body5
{ body5AdditionalMetadata = Nothing
, body5RequiredFile
}
-- ** Capitalization
-- | Capitalization
data Capitalization = Capitalization
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Enhancement: Feature Issue: Bug
2
Enhancement: Feature Issue: Bug
    Assign labels
  • Manage project labels

Milestone
3.2.2
3.2.2 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
William Cheng
Reference: OpenAPITools/openapi-generator!700
Source branch: generate_all_model

Menu

Explore Projects Groups Snippets