git.iko.soy/typeable/openapi3
on master help sign in
Merge pull request #38 from GetShopTV/fix-unused-#37

Stop producing unused definitions

commite0437b4eea6d0e82978b55fe015244defbd939d9 authorNickolay Kudasov <fizruk@users.noreply.github.com> dateMon 18 Jan 2016, 16:19 (11 years ago) parentba83080047a3fb
3 files changed+16−5
CHANGELOG.md+3−2 src/Data/Swagger/Internal/Schema.hs+5−3 test/Data/Swagger/SchemaSpec.hs+8
CHANGELOG.md+3−2
@@ -1,11 +1,12 @@
1−* Minor changes:
1+* Minor changes (see [#36](https://github.com/GetShopTV/swagger2/pull/36)):
22 * Change default `ToSchema` instance for unit data types (i.e. types with one nullable constructor like `data Unit = Unit`):
33 now these types are treated like sum types with only one alternative;
44 * Add generic `ToParamSchema` instance for unit data types;
55 * Add `items: []` to schema for `()` (making it a valid schema).
66
77* 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)).
910
10111.1.1
1112---
src/Data/Swagger/Internal/Schema.hs+5−3
@@ -448,12 +448,14 @@ instance {-# OVERLAPPING #-} Constructor c => GToSchema (C1 c U1) where
448448instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
449449 gdeclareNamedSchema opts _ s
450450 | unwrapUnaryRecords opts = fieldSchema
451− | otherwise = do
452− (_, schema) <- recordSchema
451+ | otherwise =
453452 case schema ^. schemaItems of
454453 Just (SwaggerItemsArray [_]) -> fieldSchema
455− _ -> pure (unnamed schema)
454+ _ -> do
455+ declare defs
456+ return (unnamed schema)
456457 where
458+ (defs, (_, schema)) = runDeclare recordSchema mempty
457459 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
458460 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
459461
test/Data/Swagger/SchemaSpec.hs+8
@@ -83,6 +83,7 @@ spec = do
8383 context "Character" $ checkDefs (Proxy :: Proxy Character) ["Player", "Point"]
8484 context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
8585 context "[Set (Unit, Maybe Color)]" $ checkDefs (Proxy :: Proxy [Set (Unit, Maybe Color)]) ["Unit", "Color"]
86+ context "ResourceId" $ checkDefs (Proxy :: Proxy ResourceId) []
8687 describe "Inlining Schemas" $ do
8788 context "Paint" $ checkInlinedSchema (Proxy :: Proxy Paint) paintInlinedSchemaJSON
8889 context "Character" $ checkInlinedSchema (Proxy :: Proxy Character) characterInlinedSchemaJSON
@@ -573,3 +574,10 @@ lightInlinedSchemaJSON = [aesonQQ|
573574}
574575|]
575576
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)