diff --git a/CHANGES.md b/CHANGES.md index e438ca6..9e5fb7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -135,6 +135,8 @@ To be released. ); ~~~~~~~~ + - Deprecated `uri` and `url` type is added. [[#126], [#277]] + ### Docs target - A new required configuration `targets.docs.title` was added. @@ -253,6 +255,7 @@ To be released. [#13]: https://github.com/spoqa/nirum/issues/13 [#100]: https://github.com/spoqa/nirum/issues/100 +[#126]: https://github.com/spoqa/nirum/issues/126 [#178]: https://github.com/spoqa/nirum/issues/178 [#217]: https://github.com/spoqa/nirum/issues/217 [#220]: https://github.com/spoqa/nirum/issues/220 @@ -266,6 +269,7 @@ To be released. [#267]: https://github.com/spoqa/nirum/pull/267 [#269]: https://github.com/spoqa/nirum/pull/269 [#272]: https://github.com/spoqa/nirum/pull/272 +[#277]: https://github.com/spoqa/nirum/pull/277 [entry points]: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points [python2-numbers-integral]: https://docs.python.org/2/library/numbers.html#numbers.Integral [python2-int]: https://docs.python.org/2/library/functions.html#int diff --git a/docs/serialization.md b/docs/serialization.md index c72ead6..f872380 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -184,7 +184,7 @@ a structure consists of fields which have their name and type. For example: name name, date? dob, gender? gender, - uri? website-uri + url? website-url ); It's represented in JSON to: @@ -198,7 +198,7 @@ It's represented in JSON to: }, "dob": null, "gender": "male", - "uri": null + "url": null } When a payload is deserialized, undefined fields are just ignored. @@ -229,7 +229,7 @@ a union type instead of a record type: name name, date? dob, gender? gender, - uri? website-uri + url? website-url ); It's represented in JSON to: @@ -244,7 +244,7 @@ It's represented in JSON to: }, "dob": null, "gender": "male", - "uri": null + "url": null } In a similar way to a recrod type, undefined fields in a payload are ignored diff --git a/examples/builtins.nrm b/examples/builtins.nrm index b222d63..f7f4c69 100644 --- a/examples/builtins.nrm +++ b/examples/builtins.nrm @@ -53,8 +53,8 @@ record et-cetera ( uuid b, # `uuid` stores a UUID. Represented as a string in JSON. - uri c, - # `uri` stores a URI. Represented as a string in JSON. + url c, + # `url` stores a URL. Represented as a string in JSON. ); record containers ( diff --git a/examples/pdf-service.nrm b/examples/pdf-service.nrm index cad8444..5c29941 100644 --- a/examples/pdf-service.nrm +++ b/examples/pdf-service.nrm @@ -5,12 +5,12 @@ union markdown-parse-error = symbol-error | syntax-error (text reason); type html = text; service pdf-service ( - # A microservice which renders a PDF from the given URI or HTML. + # A microservice which renders a PDF from the given URL or HTML. - @http-resource(method="GET", path="/pdf/{uri}") - binary render-uri ( - # Renders a PDF from the given URI. - uri uri, + @http-resource(method="GET", path="/pdf/{url}") + binary render-url ( + # Renders a PDF from the given URL. + url url, ), @http-resource(method="POST", path="/pdf/") diff --git a/src/Nirum/Constructs/Module.hs b/src/Nirum/Constructs/Module.hs index b228a66..c23c57d 100644 --- a/src/Nirum/Constructs/Module.hs +++ b/src/Nirum/Constructs/Module.hs @@ -30,7 +30,7 @@ import Nirum.Constructs.TypeDeclaration ( JsonType (Boolean, Number, String) , Int32 , Int64 , Text - , Uri + , Url , Uuid ) , Type (PrimitiveType) @@ -112,7 +112,9 @@ coreTypes = -- et cetera , decl' "bool" Bool Boolean , decl' "uuid" Uuid String - , decl' "uri" Uri String + , decl' "url" Url String + -- FIXME: deprecated + , decl' "uri" Url String ] where decl' name prim json = diff --git a/src/Nirum/Constructs/TypeDeclaration.hs b/src/Nirum/Constructs/TypeDeclaration.hs index 493da98..92be117 100644 --- a/src/Nirum/Constructs/TypeDeclaration.hs +++ b/src/Nirum/Constructs/TypeDeclaration.hs @@ -19,7 +19,7 @@ module Nirum.Constructs.TypeDeclaration ( EnumMember (EnumMember) , Int32 , Int64 , Text - , Uri + , Url , Uuid ) , Tag ( Tag @@ -174,7 +174,7 @@ instance Declaration Tag where -- | Primitive type identifiers. data PrimitiveTypeIdentifier = Bigint | Decimal | Int32 | Int64 | Float32 | Float64 | Text | Binary - | Date | Datetime | Bool | Uuid | Uri + | Date | Datetime | Bool | Uuid | Url deriving (Eq, Ord, Show) -- | Possible coded types of 'PrimitiveType' in JSON representation. diff --git a/src/Nirum/Targets/Python/Deserializers.hs b/src/Nirum/Targets/Python/Deserializers.hs index 4eb1603..21aad8c 100644 --- a/src/Nirum/Targets/Python/Deserializers.hs +++ b/src/Nirum/Targets/Python/Deserializers.hs @@ -578,7 +578,7 @@ except #{builtins}.ValueError: ) |] -compilePrimitiveTypeDeserializer Uri vInput vOutput vError = +compilePrimitiveTypeDeserializer Url vInput vOutput vError = compilePrimitiveTypeDeserializer Text vInput vOutput vError -- | Wrap a Python deserializer code block into an isolated scope. diff --git a/src/Nirum/Targets/Python/Serializers.hs b/src/Nirum/Targets/Python/Serializers.hs index 1cf1634..2d57161 100644 --- a/src/Nirum/Targets/Python/Serializers.hs +++ b/src/Nirum/Targets/Python/Serializers.hs @@ -80,4 +80,4 @@ compilePrimitiveTypeSerializer Datetime var = replace "$var" var [q|( )|] compilePrimitiveTypeSerializer Bool var = var compilePrimitiveTypeSerializer Uuid var = [qq|str($var).lower()|] -compilePrimitiveTypeSerializer Uri var = var +compilePrimitiveTypeSerializer Url var = var diff --git a/src/Nirum/Targets/Python/TypeExpression.hs b/src/Nirum/Targets/Python/TypeExpression.hs index 8f540fe..63ae522 100644 --- a/src/Nirum/Targets/Python/TypeExpression.hs +++ b/src/Nirum/Targets/Python/TypeExpression.hs @@ -82,8 +82,8 @@ compilePrimitiveType primitiveTypeIdentifier' = do (Uuid, _) -> do uuid <- importStandardLibrary "uuid" return [qq|$uuid.UUID|] - (Uri, Python2) -> builtins "basestring" - (Uri, Python3) -> builtins "str" + (Url, Python2) -> builtins "basestring" + (Url, Python3) -> builtins "str" where builtins :: Code -> CodeGen Code builtins typename' = do diff --git a/src/Nirum/Targets/Python/Validators.hs b/src/Nirum/Targets/Python/Validators.hs index 5dcf461..3c93357 100644 --- a/src/Nirum/Targets/Python/Validators.hs +++ b/src/Nirum/Targets/Python/Validators.hs @@ -99,9 +99,9 @@ compilePrimitiveTypeValidator primitiveTypeId pythonVar = do [ ValueValidator [qq|(($var).tzinfo is not None)|] "naive datetime (lacking tzinfo)" ] - vv Uri var = + vv Url var = [ ValueValidator [qq|('\\n' not in ($var))|] - "URI cannot contain new line characters" + "URL cannot contain new line characters" ] vv _ _ = [] diff --git a/test/Nirum/Targets/Python/TypeExpressionSpec.hs b/test/Nirum/Targets/Python/TypeExpressionSpec.hs index 87f5f57..8f1de5b 100644 --- a/test/Nirum/Targets/Python/TypeExpressionSpec.hs +++ b/test/Nirum/Targets/Python/TypeExpressionSpec.hs @@ -57,7 +57,7 @@ spec = pythonVersionSpecs $ \ ver -> do let (uuidCode, uuidContext) = run' (compilePrimitiveType Uuid) uuidCode `shouldBe` Right "_uuid.UUID" standardImports uuidContext `shouldBe` [("_uuid", "uuid")] - code (compilePrimitiveType Uri) `shouldBe` + code (compilePrimitiveType Url) `shouldBe` case ver of Python2 -> "__builtin__.basestring" Python3 -> "__builtin__.str" diff --git a/test/nirum_fixture/fixture/foo.nrm b/test/nirum_fixture/fixture/foo.nrm index e1aa071..e6a2f18 100644 --- a/test/nirum_fixture/fixture/foo.nrm +++ b/test/nirum_fixture/fixture/foo.nrm @@ -115,7 +115,7 @@ record product ( text name, int64? price, bool sale, - uri? url, + url? url, ); union animal = cat @@ -142,3 +142,5 @@ record name-shadowing-field-record ( union optional-union = foo ( int32? bar ) | baz ( int32 qux ) ; + +unboxed website (uri); diff --git a/test/nirum_fixture/fixture/types.nrm b/test/nirum_fixture/fixture/types.nrm index 9d89b1b..6bb1205 100644 --- a/test/nirum_fixture/fixture/types.nrm +++ b/test/nirum_fixture/fixture/types.nrm @@ -41,7 +41,7 @@ unboxed record-unboxed (product); union post = image (text mime-type, binary data) - | link (uri link, text title, text? quote) + | link (url link, text title, text? quote) | article (text title, text content) ; diff --git a/test/python/primitive_test.py b/test/python/primitive_test.py index 1057010..a1bb2f2 100644 --- a/test/python/primitive_test.py +++ b/test/python/primitive_test.py @@ -15,7 +15,7 @@ Point1, Point2, Point3d, Pop, PingService, Product, RecordWithMap, RecordWithOptionalRecordField, Rnb, RpcError, Run, Song, Status, Stop, Way, - WesternName) + Website, WesternName) from fixture.foo.bar import PathUnbox, IntUnbox, Point from fixture.qux import Path, Name from fixture.reserved_keyword_enum import ReservedKeywordEnum @@ -538,3 +538,15 @@ def test_name_shadowing_field(): assert "bytes must be a value of {0}, not ['invalid']".format( 'bytes' if PY3 else 'str' ) == str(ei.value) + + +def test_uri(): + """ Deprecated + """ + assert isinstance(Website, type) + website = Website(u'https://nirum.org') + assert website.value == u'https://nirum.org' + assert website.__nirum_serialize__() == u'https://nirum.org' + assert Website.__nirum_deserialize__(u'https://nirum.org') == website + with raises(ValueError): + Website(u'https://nirum.org\n')