Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for schemas with type: ["string", "null"] #747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ndbroadbent
Copy link

@ndbroadbent ndbroadbent commented Apr 13, 2020

Fixes #292

If a schema has type: ["string", "null"] or type: ["null", "integer"], etc., this change will just use the first non-null type from the array.

UPDATE: I just found some other cases where this needs to be handled: I wasn't able to update the value for any optional drop-down select lists (ListField). There might be a few other places with lines of code similar to this:

            if (!self.schema.type || self.schema.type === "string")

These will need to be updated to something like:

            if (!self.schema.type || self.schema.type === "string" || (
                Alpaca.isArray(self.schema.type) && 
                self.schema.type.length === 2 && 
                self.schema.type.indexOf("string") !== -1 && 
                self.schema.type.indexOf("null") !== -1))
            {

(But probably less verbose!)

Maybe there could be a generic "schema type checker" function that checks for any | null.

@renannprado
Copy link

Just came across alpaca for the first time and I face exactly this situation at the moment. It would be really nice if this fix is merged :D

@evaisse
Copy link

evaisse commented May 20, 2020

Hye, I've the same problems, could you merge this branch ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON Schema type: ['integer','null'] not supported
3 participants