Skip to content

Commit

Permalink
#17
Browse files Browse the repository at this point in the history
  • Loading branch information
lscalese committed Oct 14, 2023
1 parent a0fec19 commit b9c8f6f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
66 changes: 53 additions & 13 deletions src/Grongier/OpenApi/DefinitionV3.cls
Expand Up @@ -20,7 +20,12 @@ Property allowPropertyOverride As %Boolean [ InitialExpression = {$$$YES} ];

Property generateInLineModel As %Boolean [ InitialExpression = {$$$NO} ];

Method %OnNew(specification As %DynamicObject, package As %String, super As %String, compile As %Boolean, flags As %String) As %Status
Method %OnNew(
specification As %DynamicObject,
package As %String,
super As %String,
compile As %Boolean,
flags As %String) As %Status
{
Set ..spec = specification, ..package = package

Expand Down Expand Up @@ -82,7 +87,9 @@ Method GenerateClasses() As %Status
Quit sc
}

Method GenerateClassModel(schema As %DynamicObject, className As %String) As %Status
Method GenerateClassModel(
schema As %DynamicObject,
className As %String) As %Status
{
Set sc = $$$OK, requiredArray = []

Expand All @@ -104,7 +111,9 @@ Method GenerateClassModel(schema As %DynamicObject, className As %String) As %St
Quit sc
}

Method GenerateProperties(classDef As %Dictionary.ClassDefinition, properties As %DynamicObject) As %Status
Method GenerateProperties(
classDef As %Dictionary.ClassDefinition,
properties As %DynamicObject) As %Status
{
Set sc = $$$OK

Expand Down Expand Up @@ -214,7 +223,9 @@ XMLParameters
Quit
}

Method ManageAllOf(classDef As %Dictionary.ClassDefinition, schema As %DynamicObject) As %Status
Method ManageAllOf(
classDef As %Dictionary.ClassDefinition,
schema As %DynamicObject) As %Status
{
Set sc = $$$OK, superClasses = ""

Expand Down Expand Up @@ -243,7 +254,9 @@ Method ManageAllOf(classDef As %Dictionary.ClassDefinition, schema As %DynamicOb
Quit sc
}

Method ManageRequiredProperties(classDef As %Dictionary.ClassDefinition, requiredArray As %DynamicArray) As %Status
Method ManageRequiredProperties(
classDef As %Dictionary.ClassDefinition,
requiredArray As %DynamicArray) As %Status
{
Set sc = $$$OK

Expand All @@ -256,7 +269,14 @@ Method ManageRequiredProperties(classDef As %Dictionary.ClassDefinition, require
Set property = ..FindPropertyName(classDef, propertyName)
Continue:property="" ; property not found ...
Do ..log($Char(9) _ " - " _ propertyName)
Set property.Required = $$$YES

If ##class(dc.openapi.common.Utils).GetTempData("model.property.norequired", $$$NO) {
; https://github.com/lscalese/openapi-suite/issues/17
Set property.Required = $$$NO
Set property.Description = property.Description _ $Char(10) _ "/// * This property is required."
} Else {
Set property.Required = $$$YES
}
}
}

Expand Down Expand Up @@ -359,7 +379,10 @@ parametersObject
Quit
}

ClassMethod log(msg As %String, nl As %Boolean = {$$$YES}, dtOnNL As %Boolean = {$$$YES})
ClassMethod log(
msg As %String,
nl As %Boolean = {$$$YES},
dtOnNL As %Boolean = {$$$YES})
{
Quit:$Get(%zverbose)=0

Expand All @@ -370,7 +393,9 @@ ClassMethod log(msg As %String, nl As %Boolean = {$$$YES}, dtOnNL As %Boolean =
Quit
}

ClassMethod GetObjectScriptType(oaType As %DynamicObject, format As %String = "") As %String
ClassMethod GetObjectScriptType(
oaType As %DynamicObject,
format As %String = "") As %String
{

Quit:oaType="" "%VarString"
Expand Down Expand Up @@ -398,7 +423,10 @@ ClassMethod GetObjectScriptType(oaType As %DynamicObject, format As %String = ""
Quit $Get(table(oaType, format), $Get(table(oaType), "%VarString" ))
}

Method GetObjectByRef(reference As %String, Output name As %String, Output package As %String) As %DynamicObject
Method GetObjectByRef(
reference As %String,
Output name As %String,
Output package As %String) As %DynamicObject
{
; required : Do ##class(dc.openapi.common.Utils).SetTempData("model.package", ..package)
Quit ##class(dc.openapi.common.Utils).GetObjectByRef(..spec, reference, .name, .package)
Expand All @@ -410,7 +438,9 @@ ClassMethod GetSpecForPackage(package As %String) As %DynamicObject [ CodeMode =
##class(dc.openapi.common.Utils).GetSpecForPackage(package)
}

ClassMethod CreateClassDefInstance(className As %String, Output classDef As %Dictionary.ClassDefinition = "") As %Dictionary.ClassDefinition
ClassMethod CreateClassDefInstance(
className As %String,
Output classDef As %Dictionary.ClassDefinition = "") As %Dictionary.ClassDefinition
{
If $$$defClassDefined(className) {
Set sc = $$Delete^%apiOBJ(className,"-d")
Expand All @@ -429,7 +459,11 @@ ClassMethod CreateClassDefInstance(className As %String, Output classDef As %Dic
Quit $$$OK
}

Method CommonSchemaProcess(classDef As %Dictionary.ClassDefinition, propDef As %Dictionary.PropertyDefinition, schema As %DynamicObject, name As %String) As %Status
Method CommonSchemaProcess(
classDef As %Dictionary.ClassDefinition,
propDef As %Dictionary.PropertyDefinition,
schema As %DynamicObject,
name As %String) As %Status
{
Set sc = $$$OK

Expand Down Expand Up @@ -482,7 +516,9 @@ Method CommonSchemaProcess(classDef As %Dictionary.ClassDefinition, propDef As %
Quit sc
}

ClassMethod FindPropertyName(classDefinition As %Dictionary.ClassDefinition, propertyName As %String) As %Dictionary.PropertyDefinition
ClassMethod FindPropertyName(
classDefinition As %Dictionary.ClassDefinition,
propertyName As %String) As %Dictionary.PropertyDefinition
{
#dim property As %Dictionary.PropertyDefinition
Set key = ""
Expand All @@ -498,7 +534,11 @@ ClassMethod FindPropertyName(classDefinition As %Dictionary.ClassDefinition, pro
Return ""
}

ClassMethod GetClsNameForAnonymObject(path As %String = "", method As %String = "", name As %String = "", contentType As %String = "") As %String
ClassMethod GetClsNameForAnonymObject(
path As %String = "",
method As %String = "",
name As %String = "",
contentType As %String = "") As %String
{
Quit "Z"_name _ $ZCRC(path_method_name_contentType,0)
}
Expand Down
2 changes: 0 additions & 2 deletions src/dc/openapi/client/Spec.cls
Expand Up @@ -23,8 +23,6 @@ ClassMethod generateApp(
{
Set sc = $$$OK

Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation

Set spec = ##class(dc.openapi.common.SpecificationLoader).AbstractSpecLoader(spec, .sc, '$Get(features("noExtRef"),0))
Quit:$$$ISERR(sc) sc

Expand Down
1 change: 0 additions & 1 deletion src/dc/openapi/server/ServerAppGenerator.cls
Expand Up @@ -14,7 +14,6 @@ ClassMethod Generate(
{
$$$zlog("Generate server-side application " _ application)

Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation
Do ##class(community.utils.SSLClient).CreateSSLConfiguration("DefaultSSL")

Set spec = ##class(dc.openapi.common.SpecificationLoader).AbstractSpecLoader(specification, .sc, '$Get(features("noExtRef"),0))
Expand Down
23 changes: 21 additions & 2 deletions src/dc/openapi/suite/Generate.cls
Expand Up @@ -11,7 +11,10 @@ ClassMethod Client(
{
Set %zverbose = 1
Set Features("simpleHttpClientOnly") = 1


Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation
Do ..HandleCommonFeatures(.Features)

; If we have an external ref mapping, set noExtRef to 1
; It avoid validator.swagger.io to resolve external references.
If $IsObject(ExternalRefMap), '$Data(Features("noExtRef")) Set Features("noExtRef") = 1
Expand All @@ -28,6 +31,9 @@ ClassMethod ProductionClient(
Set %zverbose = 1
Set Features("simpleHttpClientOnly") = 0

Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation
Do ..HandleCommonFeatures(.Features)

; If we have an external ref mapping, set noExtRef to 1
; It avoid validator.swagger.io to resolve external references.
If $IsObject(ExternalRefMap), '$Data(Features("noExtRef")) Set Features("noExtRef") = 1
Expand All @@ -42,7 +48,10 @@ ClassMethod Server(
ExternalRefMap As %DynamicObject = "") As %Status
{
Set %zverbose = 1


Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation
Do ..HandleCommonFeatures(.Features)

; If we have an external ref mapping, set noExtRef to 1
; It avoid validator.swagger.io to resolve external references.
If $IsObject(ExternalRefMap), '$Data(Features("noExtRef")) Set Features("noExtRef") = 1
Expand All @@ -58,6 +67,8 @@ ClassMethod Models(
{
Set %zverbose = 1

Do ##class(dc.openapi.common.Utils).KillTempData() ; Kill tempory data of previous code generation

Set Features("simpleHttpClientOnly") = 1
set Features("modelOnly") = 1

Expand All @@ -68,4 +79,12 @@ ClassMethod Models(
Quit ##class(dc.openapi.client.Spec).generateApp(PackageName, Specfication, .Features, ExternalRefMap)
}

ClassMethod HandleCommonFeatures(ByRef Features As %Binary) As %Status [ Internal, Private ]
{
Quit:'$Data(Features) $$$OK
Set key = "model.property.norequired"
Do:$Data(Features(key),value) ##class(dc.openapi.common.Utils).SetTempData(key, value)
Quit $$$OK
}

}

0 comments on commit b9c8f6f

Please sign in to comment.