Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Co-authored-by: Janus <[email protected]>
Co-authored-by: Owen <[email protected]>
  • Loading branch information
3 people committed Mar 13, 2024
1 parent 60ec4db commit 72f652f
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 28 deletions.
2 changes: 2 additions & 0 deletions json-fleece-codegen-util/src/Fleece/CodeGenUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ data CodeGenDataFormat
| CodeGenEnum TypeOptions [T.Text]
| CodeGenObject TypeOptions [CodeGenObjectField] (Maybe CodeGenAdditionalProperties)
| CodeGenArray TypeOptions CodeGenObjectFieldType
| CodeGenUnionMembers [CodeGenDataFormat]

data CodeGenObjectField = CodeGenObjectField
{ codeGenFieldName :: T.Text
Expand Down Expand Up @@ -1079,6 +1080,7 @@ generateSchemaCode typeMap codeGenType = do
generateFleeceObject typeMap typeName fields mbAdditionalProperties typeOptions
CodeGenArray typeOptions itemType ->
generateFleeceArray typeMap typeName itemType typeOptions
CodeGenUnionMembers _types -> pure ([], HC.fromText "unionMembers")

let
header =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-# LANGUAGE NoImplicitPrelude #-}

module OneOfTest.Types.AStringType
( AStringType(..)
, aStringTypeSchema
) where



unionMembers
22 changes: 22 additions & 0 deletions json-fleece-openapi3/examples/one-of/OneOfTest/Types/Obj.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{-# LANGUAGE NoImplicitPrelude #-}

module OneOfTest.Types.Obj
( Obj(..)
, objSchema
) where

import Fleece.Core ((#+))
import qualified Fleece.Core as FC
import qualified OneOfTest.Types.Obj.Foobar as Foobar
import Prelude (($), Eq, Maybe, Show)

data Obj = Obj
{ foobar :: Maybe Foobar.Foobar
}
deriving (Eq, Show)

objSchema :: FC.Fleece schema => schema Obj
objSchema =
FC.object $
FC.constructor Obj
#+ FC.optional "foobar" foobar Foobar.foobarSchema
16 changes: 16 additions & 0 deletions json-fleece-openapi3/examples/one-of/OneOfTest/Types/Obj/Foobar.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{-# LANGUAGE NoImplicitPrelude #-}

module OneOfTest.Types.Obj.Foobar
( Foobar(..)
, foobarSchema
) where

import qualified Fleece.Core as FC
import Prelude (Eq, Integer, Show)

newtype Foobar = Foobar Integer
deriving (Show, Eq)

foobarSchema :: FC.Fleece schema => schema Foobar
foobarSchema =
FC.coerceSchema FC.integer
11 changes: 11 additions & 0 deletions json-fleece-openapi3/examples/one-of/codegen.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let
CodeGen =
env:CODEGEN_TEST_PRELUDE
? ../../../json-fleece-codegen-util/codegen-prelude.dhall
in
\(rootDir : Text) ->
CodeGen.baseConfig //
{ moduleBaseName = "OneOfTest"
, inputFileName = "${rootDir}/one-of.yaml"
, destination = rootDir
}
165 changes: 165 additions & 0 deletions json-fleece-openapi3/examples/one-of/one-of.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: one-of
version: 0.1.0.0
category: Web
homepage: https://github.com/githubuser/one-of
author: Author name here
maintainer: [email protected]
copyright: 2023 Author name here
license: BSD3
build-type: Simple

library
exposed-modules:
OneOfTest.Operations.GetMultiplePathsParams
OneOfTest.Operations.GetMultiplePathsParams.Param1
OneOfTest.Operations.GetMultiplePathsParams.Param2
OneOfTest.Operations.Num2GetAResultNamedNumberSomething
OneOfTest.Operations.ParamSchemaReference
OneOfTest.Operations.ParamSchemaReference.EnumIntParam
OneOfTest.Operations.ParamSchemaReference.EnumParam
OneOfTest.Operations.ParamSchemaReference.StringParam
OneOfTest.Operations.ParamSchemaReferenceArray
OneOfTest.Operations.ParamSchemaReferenceArray.ArrayParam
OneOfTest.Operations.TestCases.AnyJsonResponse
OneOfTest.Operations.TestCases.HeaderParams
OneOfTest.Operations.TestCases.HeaderParams.BooleanParam
OneOfTest.Operations.TestCases.HeaderParams.InlineEnumIntParam
OneOfTest.Operations.TestCases.HeaderParams.InlineEnumParam
OneOfTest.Operations.TestCases.HeaderParams.OptionalArrayParam
OneOfTest.Operations.TestCases.HeaderParams.RequiredArrayParam
OneOfTest.Operations.TestCases.HeaderParams.StringParam
OneOfTest.Operations.TestCases.InlineArrayResponse
OneOfTest.Operations.TestCases.InlineBooleanResponse
OneOfTest.Operations.TestCases.InlineEnumArrayRequestBody
OneOfTest.Operations.TestCases.InlineEnumArrayRequestBody.RequestBodyItem
OneOfTest.Operations.TestCases.InlineEnumResponses
OneOfTest.Operations.TestCases.InlineEnumResponses.Response200Body
OneOfTest.Operations.TestCases.InlineEnumResponses.Response201Body
OneOfTest.Operations.TestCases.InlineInt32Response
OneOfTest.Operations.TestCases.InlineInt64Response
OneOfTest.Operations.TestCases.InlineIntegerResponse
OneOfTest.Operations.TestCases.InlineObjectAdditionalPropertiesJsonResponse
OneOfTest.Operations.TestCases.InlineObjectJsonResponse
OneOfTest.Operations.TestCases.InlineObjectStringArrayResponse
OneOfTest.Operations.TestCases.InlineObjectStringRefResponse
OneOfTest.Operations.TestCases.InlineObjectStringResponse
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesAndAdditionalJsonResponse
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesAndAdditionalJsonResponse.Response200Body
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesAndAdditionalJsonResponse.Response200Body.Bar
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesAndAdditionalJsonResponse.Response200Body.Foo
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesAndAdditionalJsonResponse.Response200BodyItem
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesJsonResponse
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesJsonResponse.Response200Body
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesJsonResponse.Response200Body.Bar
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesJsonResponse.Response200Body.Baz
OneOfTest.Operations.TestCases.InlineObjectWithPropertiesJsonResponse.Response200Body.Foo
OneOfTest.Operations.TestCases.InlineStringResponse
OneOfTest.Operations.TestCases.MultipleResponsesCodes
OneOfTest.Operations.TestCases.NoContentResponse
OneOfTest.Operations.TestCases.OperationTypeOptions.PathParam
OneOfTest.Operations.TestCases.OperationTypeOptions.PathParam.PathParam
OneOfTest.Operations.TestCases.OperationTypeOptions.PathParam.QueryParam
OneOfTest.Operations.TestCases.QueryParams
OneOfTest.Operations.TestCases.QueryParams.BooleanParam
OneOfTest.Operations.TestCases.QueryParams.InlineEnumIntParam
OneOfTest.Operations.TestCases.QueryParams.InlineEnumParam
OneOfTest.Operations.TestCases.QueryParams.OptionalArrayParam
OneOfTest.Operations.TestCases.QueryParams.RequiredArrayParam
OneOfTest.Operations.TestCases.QueryParams.StringParam
OneOfTest.Operations.TestCases.RequestBody
OneOfTest.Types.AStringType
OneOfTest.Types.CustomDateFormat
OneOfTest.Types.DateTimeFormats
OneOfTest.Types.DateTimeFormats.DefaultTimeField
OneOfTest.Types.DateTimeFormats.LocalTimeField
OneOfTest.Types.DateTimeFormats.UtcTimeField
OneOfTest.Types.DateTimeFormats.ZonedTimeField
OneOfTest.Types.DefaultTimeType
OneOfTest.Types.DerivingNothing
OneOfTest.Types.EnumIntParam
OneOfTest.Types.EnumParam
OneOfTest.Types.FieldDescriptions
OneOfTest.Types.FieldDescriptions.EmptyDescription
OneOfTest.Types.FieldDescriptions.NoDescription
OneOfTest.Types.FieldDescriptions.WithDescription
OneOfTest.Types.FieldTestCases
OneOfTest.Types.FieldTestCases.ArrayFieldItem
OneOfTest.Types.FieldTestCases.NullableArrayFieldItem
OneOfTest.Types.FieldTestCases.OptionalArrayFieldItem
OneOfTest.Types.FieldTestCases.OptionalField
OneOfTest.Types.FieldTestCases.OptionalNullableArrayFieldItem
OneOfTest.Types.FieldTestCases.OptionalNullableField
OneOfTest.Types.FieldTestCases.RequiredField
OneOfTest.Types.FieldTestCases.RequiredNullableField
OneOfTest.Types.JustAdditionalPropertiesSchemaInline
OneOfTest.Types.JustAdditionalPropertiesSchemaInlineItem
OneOfTest.Types.JustAdditionalPropertiesSchemaRef
OneOfTest.Types.JustAdditionalPropertiesTrue
OneOfTest.Types.LocalTimeType
OneOfTest.Types.MixedInAdditionalPropertiesTrue
OneOfTest.Types.MixedInAdditionalPropertiesTrue.Bar
OneOfTest.Types.MixedInAdditionalPropertiesTrue.Foo
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaInline
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaInline.Bar
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaInline.Foo
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaInlineItem
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaRef
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaRef.Bar
OneOfTest.Types.MixedInJustAdditionalPropertiesSchemaRef.Foo
OneOfTest.Types.NameConflicts
OneOfTest.Types.NameConflicts.Case
OneOfTest.Types.NameConflicts.Class
OneOfTest.Types.NameConflicts.Data
OneOfTest.Types.NameConflicts.Deriving
OneOfTest.Types.NameConflicts.Do
OneOfTest.Types.NameConflicts.Else
OneOfTest.Types.NameConflicts.If
OneOfTest.Types.NameConflicts.Import
OneOfTest.Types.NameConflicts.In
OneOfTest.Types.NameConflicts.Infix
OneOfTest.Types.NameConflicts.Infixl
OneOfTest.Types.NameConflicts.Infixr
OneOfTest.Types.NameConflicts.Instance
OneOfTest.Types.NameConflicts.Int32
OneOfTest.Types.NameConflicts.Int64
OneOfTest.Types.NameConflicts.Let
OneOfTest.Types.NameConflicts.Module
OneOfTest.Types.NameConflicts.NameConflicts
OneOfTest.Types.NameConflicts.Newtype
OneOfTest.Types.NameConflicts.Of
OneOfTest.Types.NameConflicts.Scientific
OneOfTest.Types.NameConflicts.Text
OneOfTest.Types.NameConflicts.Then
OneOfTest.Types.NameConflicts.Type
OneOfTest.Types.NameConflicts.Where
OneOfTest.Types.Num2SchemaStartingWithNumber
OneOfTest.Types.StringParam
OneOfTest.Types.TestCases.InlineObjectWithPropertiesJsonResponse.Response200Body.Baz.Bax
OneOfTest.Types.TopLevelArray
OneOfTest.Types.TopLevelArray.TopLevelArrayItem
OneOfTest.Types.TopLevelArrayNullable
OneOfTest.Types.TopLevelArrayNullable.TopLevelArrayNullableItem
OneOfTest.Types.UtcTimeType
OneOfTest.Types.ZonedTimeType
other-modules:
Paths_one_of
hs-source-dirs:
./
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base >=4.7 && <5
, beeline-http-client ==0.8.*
, beeline-routing >=0.2.4 && <0.3
, containers
, json-fleece-aeson-beeline ==0.1.*
, json-fleece-core >=0.1.3 && <0.7
, scientific
, text
, time
default-language: Haskell2010
16 changes: 16 additions & 0 deletions json-fleece-openapi3/examples/one-of/one-of.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.1
info:
title: Fleece TestCases
version: 1.0.0
components:
schemas:
AStringType:
oneOf:
- type: string
- type: integer
- $ref: "#/components/schemas/Obj"
Obj:
type: object
properties:
foobar:
type: integer
35 changes: 35 additions & 0 deletions json-fleece-openapi3/examples/one-of/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: one-of
version: 0.1.0.0
#synopsis:
#description:
homepage: https://github.com/githubuser/one-of
license: BSD3
author: Author name here
maintainer: [email protected]
copyright: 2023 Author name here
category: Web

dependencies:
- base >= 4.7 && < 5
- containers
- text
- scientific
- json-fleece-core >= 0.1.3 && < 0.7
- json-fleece-aeson-beeline >= 0.1 && < 0.2
- beeline-routing >= 0.2.4 && < 0.3
- beeline-http-client >= 0.8 && < 0.9
- time

ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints

library:
source-dirs: .
61 changes: 61 additions & 0 deletions json-fleece-openapi3/examples/one-of/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/19.yaml
system-ghc: true
install-ghc: false

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
extra-deps:
- ../../../json-fleece-core
- ../../../json-fleece-aeson
- ../../../json-fleece-aeson-beeline
- git: https://github.com/flipstone/beeline
commit: 5545ee24e04cebd2182a924033fa174381591107
subdirs:
- beeline-routing
- beeline-http-client
- git: https://github.com/flipstone/shrubbery
commit: 730255546c2eb99071380db44b5e349318dead68
- non-empty-text-0.2.0@sha256:7d1c1f9a11c78c00c656269f940d2fcccd3c2eaf6b619f66bb83a9ea72decc1f,2438

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of Stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.9"
#
# Override the architecture used by Stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by Stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
Loading

0 comments on commit 72f652f

Please sign in to comment.