git.iko.soy/typeable/openapi3
on master help sign in
Merge pull request #38 from GetShopTV/fix-unused-#37
e0437b4Nickolay Kudasov
CHANGELOG.md+3−2
@@ -1,11 +1,12 @@
1−* Minor changes:
1+* Minor changes (see [#36](https://github.com/GetShopTV/swagger2/pull/36)):
2 * Change default `ToSchema` instance for unit data types (i.e. types with one nullable constructor like `data Unit = Unit`):
2 * Change default `ToSchema` instance for unit data types (i.e. types with one nullable constructor like `data Unit = Unit`):
3 now these types are treated like sum types with only one alternative;
3 now these types are treated like sum types with only one alternative;
4 * Add generic `ToParamSchema` instance for unit data types;
4 * Add generic `ToParamSchema` instance for unit data types;
5 * Add `items: []` to schema for `()` (making it a valid schema).
5 * Add `items: []` to schema for `()` (making it a valid schema).
6
6
7* Fixes:
7* Fixes:
8− * `items: []` is not omitted from `Schema` JSON.
8+ * Do not omit `items: []` from `Schema` JSON;
9+ * Do not generate unused definitions for nested `newtype`s (see [#38](https://github.com/GetShopTV/swagger2/pull/38)).
9
10
101.1.1
111.1.1
11---
12---
src/Data/Swagger/Internal/Schema.hs+5−3
@@ -448,12 +448,14 @@ instance {-# OVERLAPPING #-} Constructor c => GToSchema (C1 c U1) where
448instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
448instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
449 gdeclareNamedSchema opts _ s
449 gdeclareNamedSchema opts _ s
450 | unwrapUnaryRecords opts = fieldSchema
450 | unwrapUnaryRecords opts = fieldSchema
451− | otherwise = do
451+ | otherwise =
452− (_, schema) <- recordSchema
453 case schema ^. schemaItems of
452 case schema ^. schemaItems of
454 Just (SwaggerItemsArray [_]) -> fieldSchema
453 Just (SwaggerItemsArray [_]) -> fieldSchema
454+ _ -> do
455+ declare defs
455− _ -> pure (unnamed schema)
456+ return (unnamed schema)
456 where
457 where
458+ (defs, (_, schema)) = runDeclare recordSchema mempty
457 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
459 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
458 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
460 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
459
461
test/Data/Swagger/SchemaSpec.hs+8
@@ -83,6 +83,7 @@ spec = do
83 context "Character" $ checkDefs (Proxy :: Proxy Character) ["Player", "Point"]
83 context "Character" $ checkDefs (Proxy :: Proxy Character) ["Player", "Point"]
84 context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
84 context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
85 context "[Set (Unit, Maybe Color)]" $ checkDefs (Proxy :: Proxy [Set (Unit, Maybe Color)]) ["Unit", "Color"]
85 context "[Set (Unit, Maybe Color)]" $ checkDefs (Proxy :: Proxy [Set (Unit, Maybe Color)]) ["Unit", "Color"]
86+ context "ResourceId" $ checkDefs (Proxy :: Proxy ResourceId) []
86 describe "Inlining Schemas" $ do
87 describe "Inlining Schemas" $ do
87 context "Paint" $ checkInlinedSchema (Proxy :: Proxy Paint) paintInlinedSchemaJSON
88 context "Paint" $ checkInlinedSchema (Proxy :: Proxy Paint) paintInlinedSchemaJSON
88 context "Character" $ checkInlinedSchema (Proxy :: Proxy Character) characterInlinedSchemaJSON
89 context "Character" $ checkInlinedSchema (Proxy :: Proxy Character) characterInlinedSchemaJSON
@@ -573,3 +574,10 @@ lightInlinedSchemaJSON = [aesonQQ|
573}
574}
574|]
575|]
575
576
577+-- ========================================================================
578+-- ResourceId (series of newtypes)
579+-- ========================================================================
580+
581+newtype Id = Id String deriving (Generic, ToSchema)
582+
583+newtype ResourceId = ResourceId Id deriving (Generic, ToSchema)