Skip to content

WIP: Nested types#1

Merged
dvdsgl merged 3 commits into
masterfrom
proper-types
Jul 14, 2017
Merged

WIP: Nested types#1
dvdsgl merged 3 commits into
masterfrom
proper-types

Conversation

@dvdsgl

@dvdsgl dvdsgl commented Jul 13, 2017

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/Main.purs Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend that we don't use StrMap in our model. It's just a lightweight alias for a foreign JavaScript object, and we'll have an easier time if we just use Array or Map.

Comment thread src/Main.purs Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could do:

(case _ of
  [] -> ...
  x : xs -> ...)

Comment thread src/Main.purs Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSArray :: CSharpType -> CSharpType, so I am not sure how you are applying it to a record here.

Comment thread src/Main.purs Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write { x, ... } instead of { x: x, ... }.

@dvdsgl

dvdsgl commented Jul 13, 2017

Copy link
Copy Markdown
Member Author

Using let instead of where within those lambdas made it work:

gatherCSharpClassesFromJson :: String -> Json -> Tuple CSharpType (Array CSharpClass)
gatherCSharpClassesFromJson name json = foldJson
    (const $ Tuple CSObject [])
    (\b -> Tuple CSBool [])
    (\x -> Tuple CSDouble [])
    (\s -> Tuple CSString [])
    (case _ of
        [] -> Tuple (CSArray CSObject) []
        x : _ ->
            let Tuple et classes = gatherCSharpClassesFromJson (singularize name) x in
            Tuple (CSArray et) classes)
    (\o ->
        let c = CSClass { name: name, properties: props }
            Tuple props classes = mapProperties o in
        Tuple (CSClassType c) (c : classes))
    json

@dvdsgl

dvdsgl commented Jul 13, 2017

Copy link
Copy Markdown
Member Author

Pulling the lambdas our into their own definitions also worked:

gatherCSharpClassesFromJson name json = foldJson
    (const $ Tuple CSObject [])
    (\b -> Tuple CSBool [])
    (\x -> Tuple CSDouble [])
    (\s -> Tuple CSString [])
    fromJArray
    fromJObject
    json
    where
        fromJObject o = Tuple (CSClassType c) (c : classes)
            where c = CSClass { name: name, properties: props }
                  Tuple props classes = mapProperties o
        
        fromJArray [] = Tuple (CSArray CSObject) []
        fromJArray (x : _) = Tuple (CSArray et) classes
            where Tuple et classes = gatherCSharpClassesFromJson (singularize name) x

@dvdsgl
dvdsgl merged commit 3072488 into master Jul 14, 2017
@dvdsgl
dvdsgl deleted the proper-types branch July 19, 2017 02:18
schani pushed a commit that referenced this pull request Aug 29, 2017
WIP: Nested types

Original commit 3072488
schani added a commit to thives/quicktype that referenced this pull request Jul 19, 2026
…eapps#1)

Replace the Vitest unit test (which checked Rust output strings for one
language) with a standard JSON Schema fixture exercising the same shape:
an allOf nested inside a oneOf inside another oneOf, taken from the
issue glideapps#2913 repro. The fixture runs against every language in CI,
round-trips a positive instance, and expects failure on a malformed
union member for languages with the "union" feature.

Verified end-to-end locally with schema-golang and schema-typescript;
all 22 CI target languages generate successfully from the schema.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants