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

Update to Elm 0.19.1; fix tests #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"elm/regex": "1.0.0 <= v < 2.0.0",
"zwilias/elm-utf-tools": "2.0.1 <= v < 3.0.0"
},
"test-dependencies": {}
}
"test-dependencies": {
"elm-explorations/test": "1.2.2 <= v < 2.0.0"
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"generate-tests": "node ./generate-tests.js draft-6 > tests/Draft6.elm && node ./generate-tests.js draft-4 > tests/Draft4.elm"
},
"devDependencies": {
"elm": "^0.18.0",
"elm-live": "^2.7.4",
"elm-test": "^0.18.7"
"elm": "^0.19.1-5",
"elm-live": "^4.0.2",
"elm-test": "^0.19.1"
},
"dependencies": {
"elm-format": "^0.8.5",
"gh-pages": "^1.0.0"
}
}
9 changes: 4 additions & 5 deletions src/Json/Schema.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import Json.Decode exposing (Value, decodeString, decodeValue)
import Json.Schema.Definitions exposing (Schema, decoder)
import Json.Schema.Helpers exposing (collectIds)
import Json.Schema.Validation exposing (Error, JsonPointer, ValidationError(..), ValidationOptions, validate)
import Json.Schemata
import Ref exposing (SchemataPool, defaultPool)
import Ref


{-| Validate value against JSON Schema. Returns Result with updated value in case if validationOptions require so.
Expand All @@ -42,7 +41,7 @@ validateValue : ValidationOptions -> Value -> Schema -> Result (List Error) Valu
validateValue validationOptions value schema =
let
( pool, _ ) =
collectIds schema defaultPool
collectIds schema Ref.defaultPool
in
validate validationOptions pool value schema schema

Expand All @@ -53,10 +52,10 @@ validateAt : ValidationOptions -> Value -> Schema -> String -> Result (List Erro
validateAt validationOptions value schema uri =
let
( pool, _ ) =
collectIds schema defaultPool
collectIds schema Ref.defaultPool
in
case Ref.resolveReference "" pool schema uri of
Just ( ns, resolvedSchema ) ->
Just ( _, resolvedSchema ) ->
validate validationOptions pool value schema resolvedSchema

Nothing ->
Expand Down
11 changes: 5 additions & 6 deletions src/Json/Schema/Builder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ validate validationOptions val sb =
Ok schema ->
Validation.validate validationOptions Ref.defaultPool val schema schema

Err s ->
Err _ ->
Ok val


Expand Down Expand Up @@ -621,12 +621,11 @@ exclusiveBoundaryToString eb =

boolToString : Bool -> String
boolToString b =
case b of
True ->
"true"
if b then
"true"

False ->
"false"
else
"false"


{-| Encode schema into a builder code (elm)
Expand Down
9 changes: 3 additions & 6 deletions src/Json/Schema/Definitions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Feel free to open [issue](https://github.com/1602/json-schema) to describe your
-}

import Json.Decode as Decode exposing (Decoder, Value, andThen, bool, fail, field, float, int, lazy, list, nullable, string, succeed, value)
import Json.Decode.Pipeline as DecodePipeline exposing (optional, optionalAt, required, requiredAt)
import Json.Decode.Pipeline as DecodePipeline exposing (optional, requiredAt)
import Json.Encode as Encode
import Util exposing (foldResults, isInt, resultToDecoder)
import Util exposing (foldResults, resultToDecoder)


{-| Schema can be either boolean or actual object containing validation and meta properties
Expand Down Expand Up @@ -182,10 +182,6 @@ blankSubSchema =
}


type RowEncoder a
= RowEncoder (Maybe a) String (a -> Value)


{-| -}
encode : Schema -> Value
encode s =
Expand Down Expand Up @@ -591,6 +587,7 @@ singleTypeDecoder s =
schemataDecoder : Decoder Schemata
schemataDecoder =
Decode.keyValuePairs (lazy (\_ -> decoder))
|> Decode.andThen (\x -> succeed <| List.reverse x)
|> Decode.map Schemata


Expand Down
3 changes: 1 addition & 2 deletions src/Json/Schema/Examples.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Json.Schema.Examples exposing (bookingSchema, coreSchemaDraft6)

import Json.Decode
import Json.Encode as Encode
import Json.Schema.Builder exposing (..)
import Json.Schema.Definitions exposing (Schema, blankSchema)
Expand Down Expand Up @@ -50,7 +49,7 @@ coreSchemaDraft6 =
, ( "stringArray"
, buildSchema
|> withType "array"
|> withDefault ([] |> Encode.list)
|> withDefault (Encode.list Encode.object [])
|> withItem (buildSchema |> withType "string")
)
]
Expand Down
68 changes: 6 additions & 62 deletions src/Json/Schema/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Json.Schema.Helpers exposing

)

import Dict exposing (Dict)
import Json.Decode as Decode exposing (Value, decodeString, decodeValue)
import Dict
import Json.Decode as Decode
import Json.Encode as Encode
import Json.Schema.Definitions as Schema
exposing
Expand All @@ -25,10 +25,8 @@ import Json.Schema.Definitions as Schema
, SingleType(..)
, SubSchema
, Type(..)
, blankSchema
, blankSubSchema
)
import Ref exposing (SchemataPool, parseJsonPointer, resolveReference)
import Ref exposing (SchemataPool, parseJsonPointer)


type alias ImpliedType =
Expand Down Expand Up @@ -169,40 +167,6 @@ makeJsonPointer ( isPointer, ns, path ) =
}

-}


getListItem : Int -> List a -> Maybe a
getListItem index list =
let
( _, result ) =
List.foldl
(\item ( i, resultLocal ) ->
if index == i then
( i + 1, Just item )

else
( i + 1, resultLocal )
)
( 0, Nothing )
list
in
result


setListItem : Int -> a -> List a -> List a
setListItem index a list =
List.indexedMap
(\i item ->
if index == i then
a

else
item
)
list



{-
calcSubSchemaType : Maybe Value -> Schema -> SubSchema -> Maybe ( Type, SubSchema )
calcSubSchemaType actualValue schema os =
Expand Down Expand Up @@ -395,26 +359,6 @@ setListItem index a list =
)
Nothing
-}


encodeDict : Dict String Value -> Value
encodeDict dict =
Encode.object (Dict.toList dict)


decodeDict : Value -> Dict String Value
decodeDict val =
Decode.decodeValue (Decode.dict Decode.value) val
|> Result.withDefault Dict.empty


decodeList : Value -> List Value
decodeList val =
Decode.decodeValue (Decode.list Decode.value) val
|> Result.withDefault []



{-
getDefinition : Maybe Schemata -> String -> Maybe Schema
getDefinition defs name =
Expand Down Expand Up @@ -478,15 +422,15 @@ collectIds schema pool =
case uri of
Just s ->
let
( isPointer, ns, _ ) =
( _, ns, _ ) =
parseJsonPointer s ""
in
ns

Nothing ->
""

manageId : String -> Value -> SchemataPool -> List ( String, Value ) -> ( List ( String, Value ), ( SchemataPool, String ) )
manageId : String -> Encode.Value -> SchemataPool -> List ( String, Encode.Value ) -> ( List ( String, Encode.Value ), ( SchemataPool, String ) )
manageId ns source poolLocal obj =
case List.filter (\( name, _ ) -> name == "id" || name == "$id") obj of
( _, val ) :: _ ->
Expand Down Expand Up @@ -515,7 +459,7 @@ collectIds schema pool =
|> Decode.decodeValue (Decode.keyValuePairs Decode.value)
|> Result.withDefault []
|> manageId ns source poolLocal
|> (\( list, res ) -> List.foldl (\( key, val ) -> walkValue val) res list)
|> (\( list, res ) -> List.foldl (\( _, val ) -> walkValue val) res list)
in
case schema of
ObjectSchema { id, source } ->
Expand Down
14 changes: 3 additions & 11 deletions src/Json/Schema/Random.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Experimental module.
-}

import Char
import Dict
import Json.Encode as Encode exposing (Value)
import Json.Schema.Definitions
exposing
Expand All @@ -31,7 +30,7 @@ import Json.Schema.Definitions
, Type(..)
)
import Json.Schema.Helpers exposing (collectIds)
import Random exposing (Generator, Seed)
import Random exposing (Generator)
import Ref exposing (defaultPool)
import Util exposing (getAt, uncons)

Expand Down Expand Up @@ -223,13 +222,6 @@ valueAt settings s ref =
let
( pool, ns ) =
collectIds s defaultPool

--|> Debug.log "pool is"
a =
pool
|> Dict.keys

-- |> Debug.log "pool keys are"
in
case Ref.resolveReference ns pool s ref of
Just ( nsLocal, ss ) ->
Expand Down Expand Up @@ -267,14 +259,14 @@ valueGenerator settings ns pool schema =
Nothing ->
nullGenerator

Just ( nsLocal, BooleanSchema b ) ->
Just ( _, BooleanSchema b ) ->
if b then
randomBool |> Random.map (\_ -> Encode.object [])

else
randomBool |> Random.map (\_ -> Encode.null)

Just ( nsLocal, ObjectSchema os ) ->
Just ( _, ObjectSchema os ) ->
[ Maybe.andThen uncons os.examples
|> Maybe.map randomItemFromList
, Maybe.andThen uncons os.enum
Expand Down
Loading