Bug Report Checklist
Description
Generation of Crystal client using Free-Form object results in compile time error Error: undefined constant AnyType.
Free-form objects are described here: https://swagger.io/docs/specification/data-models/dictionaries/#free-form
Free-Form Objects
If the dictionary values can be of any type (aka free-form object), use additionalProperties: true:
type: object
additionalProperties: true
This is equivalent to:
type: object
additionalProperties: {}
Running crystal spec results in the following:
% crystal spec
Showing last frame. Use --error-trace for full trace.
In src/addlprops/models/pet.cr:27:34
27 | property info : Hash(String, AnyType)?
^------
Error: undefined constant AnyType
This is due to the following generated code:
# Optional properties
@[JSON::Field(key: "info", type: Hash(String, AnyType)?, nillable: true, emit_null: false)]
property info : Hash(String, AnyType)?
Ref: https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/src/addlprops/models/pet.cr#L25-L27
openapi-generator version
The following versions have been tested:
- 6.2.0
- openapi-generator-cli-7.0.0-20221012.083708-4.jar
OpenAPI declaration file content or url
The entire spec is here:
https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/spec_addlprop_oas3.yaml
The definition causing the issue is here:
info:
type: object
additionalProperties: {}
The same result occurs for:
info:
type: object
additionalProperties: true
Ref: https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/spec_addlprop_oas3.yaml#L42-L44
Generation Details
The generation command is here:
java -jar openapi-generator-cli.jar generate -i addlprop_spec.json -g crystal -o addlprops --additional-properties=shardName=addlprops,moduleName=Addlprops,shardLicense=MIT,shardVersion=0.1.0,shardAuthors=grokify,shardDescription=Additional\ Properties\ demo
Ref: https://github.com/grokify/crystal-addlprops/blob/d504e1da60eb1790f0972231d88f99871ec3a93a/generator.sh#L1
Steps to reproduce
- Run generator command to create the API client
cd addlprops
- Patch
src/addlprops/configuration.cr for issue Error: for empty hashes use '{} of KeyType => ValueType' by turning {} to Hash(String, String).new as seen here: https://github.com/grokify/crystal-addlprops/blob/d504e1da60eb1790f0972231d88f99871ec3a93a/src/addlprops/configuration.cr#L218-L221
shards install
crystal spec
Related issues/PRs
None
Suggest a fix
I was able to compile the client by changing Hash(String, AnyType) to Hash(String, Object).
Bug Report Checklist
Description
Generation of Crystal client using Free-Form object results in compile time error
Error: undefined constant AnyType.Free-form objects are described here: https://swagger.io/docs/specification/data-models/dictionaries/#free-form
Running
crystal specresults in the following:This is due to the following generated code:
Ref: https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/src/addlprops/models/pet.cr#L25-L27
openapi-generator version
The following versions have been tested:
OpenAPI declaration file content or url
The entire spec is here:
https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/spec_addlprop_oas3.yaml
The definition causing the issue is here:
The same result occurs for:
Ref: https://github.com/grokify/crystal-addlprops/blob/a07dab7def7d699cb52b30cd354cfd181e9cd6a4/spec_addlprop_oas3.yaml#L42-L44
Generation Details
The generation command is here:
java -jar openapi-generator-cli.jar generate -i addlprop_spec.json -g crystal -o addlprops --additional-properties=shardName=addlprops,moduleName=Addlprops,shardLicense=MIT,shardVersion=0.1.0,shardAuthors=grokify,shardDescription=Additional\ Properties\ demoRef: https://github.com/grokify/crystal-addlprops/blob/d504e1da60eb1790f0972231d88f99871ec3a93a/generator.sh#L1
Steps to reproduce
cd addlpropssrc/addlprops/configuration.crfor issueError: for empty hashes use '{} of KeyType => ValueType'by turning{}toHash(String, String).newas seen here: https://github.com/grokify/crystal-addlprops/blob/d504e1da60eb1790f0972231d88f99871ec3a93a/src/addlprops/configuration.cr#L218-L221shards installcrystal specRelated issues/PRs
None
Suggest a fix
I was able to compile the client by changing
Hash(String, AnyType)toHash(String, Object).