[elixir] Typespec - allow null on optional struct-attributes#1514
Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom Nov 29, 2018
Merged
[elixir] Typespec - allow null on optional struct-attributes#1514wing328 merged 5 commits intoOpenAPITools:masterfrom
wing328 merged 5 commits intoOpenAPITools:masterfrom
Conversation
Member
|
@mrmstn thanks for the PR. Shall we also use the Ref:
|
Contributor
Author
|
I think this would be a good idea - I kind of missed the existance of |
4 tasks
Contributor
Author
|
I also added the nullable type to the musache file. Based on the following swagger 2.0 defintion definitions:
Entity:
type: object
properties:
requiredDate:
type: string
format: date
x-nullable: false
notRequiredDate:
type: string
format: date
x-nullable: false
nullableRequiredDate:
type: string
format: date
x-nullable: true
nullableNotRequiredDate:
type: string
format: date
x-nullable: true
required:
- requiredDate
- nullableRequiredDatethis PR will result to the following results defmodule SwaggerPetstore.Model.Entity do
@moduledoc """
"""
@derive [Poison.Encoder]
defstruct [
:"requiredDate",
:"notRequiredDate",
:"nullableRequiredDate",
:"nullableNotRequiredDate"
]
@type t :: %__MODULE__{
:"requiredDate" => Date.t,
:"notRequiredDate" => Date.t | nil,
:"nullableRequiredDate" => Date.t | nil,
:"nullableNotRequiredDate" => Date.t | nil
}
endAs you can see, even if you didn't allow a non required attribute to be null, the typespec will mark the attribute as possible null. This is given to the fact that elixir will initiate all attributes in a struct as null and therefore a "optional" attribute in a struct can only be null and not "not present" |
A-Joshi
pushed a commit
to ihsmarkitoss/openapi-generator
that referenced
this pull request
Feb 27, 2019
…Tools#1514) * Typespec - allow null on optional parameters * Run Petstore for elixir * considers 'nullable' in model template, fixes 'isRequired'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif 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\.master,3.4.x,4.0.x. Default:master.Description of the PR
This PR allows null-values for struct-attributes which are not marked as required. This is very important since the compiler would mark this as a error since a null value in a struct would break the typespec contract.
With this small typespec fix, non-required and nullable attributes will be markes as possible nil values for the given model