Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename uri to url (uri remains deprecated) #277

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/builtins.nrm
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions examples/pdf-service.nrm
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
6 changes: 4 additions & 2 deletions src/Nirum/Constructs/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Nirum.Constructs.TypeDeclaration ( JsonType (Boolean, Number, String)
, Int32
, Int64
, Text
, Uri
, Url
, Uuid
)
, Type (PrimitiveType)
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions src/Nirum/Constructs/TypeDeclaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Nirum.Constructs.TypeDeclaration ( EnumMember (EnumMember)
, Int32
, Int64
, Text
, Uri
, Url
, Uuid
)
, Tag ( Tag
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Nirum/Targets/Python/Deserializers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Nirum/Targets/Python/Serializers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/Nirum/Targets/Python/TypeExpression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Nirum/Targets/Python/Validators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ _ = []

Expand Down
2 changes: 1 addition & 1 deletion test/Nirum/Targets/Python/TypeExpressionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion test/nirum_fixture/fixture/foo.nrm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ record product (
text name,
int64? price,
bool sale,
uri? url,
url? url,
);

union animal = cat
Expand All @@ -142,3 +142,5 @@ record name-shadowing-field-record (
union optional-union = foo ( int32? bar )
| baz ( int32 qux )
;

unboxed website (uri);
2 changes: 1 addition & 1 deletion test/nirum_fixture/fixture/types.nrm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;

Expand Down
14 changes: 13 additions & 1 deletion test/python/primitive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')