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

Custom errors #52

Merged
merged 11 commits into from
Jan 17, 2024
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
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.3-beta.1] - 2023-11-17

### Added

- Custom error handling:
- Now generates a custom error type for each endpoint that has a non-2xx responses.

## [0.1.2] - 2023-11-13

### Fixed

- I published the wrong build for 0.1.1, this published the correct build. See 0.1.1 for changes.

## [0.1.1] - 2023-11-01

### Fixed

- [incorrect parsing of JSON files](https://github.com/wolfadex/elm-open-api-cli/issues/53)

- Resolved by https://github.com/wolfadex/elm-open-api-cli/pull/54/, by @lawik

## [0.1.0] - 2023-10-06

### Initial release
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elm-open-api",
"version": "0.1.2",
"version": "0.1.3-beta.1",
"description": "A tool for generating Elm SDKs from OpenAPI Specs.",
"main": "dist/elm-open-api.js",
"bin": "dist/elm-open-api.js",
Expand All @@ -12,7 +12,8 @@
"review:watch": "elm-review --watch --fix",
"format": "elm-format src tests --validate",
"test": "elm-test",
"test:watch": "elm-test --watch"
"test:watch": "elm-test --watch",
"publish": "npm run build && npm publish"
},
"author": "Wolfgang Schuster",
"license": "MIT",
Expand Down
44 changes: 43 additions & 1 deletion src/CliMonad.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
module CliMonad exposing (CliMonad, Warning, andThen, andThen2, combine, combineMap, errorToWarning, fail, fromApiSpec, map, map2, map3, recordType, refToTypeName, run, stepOrFail, succeed, todo, todoWithDefault, typeToAnnotation, typeToAnnotationMaybe, withPath, withWarning)
module CliMonad exposing
( CliMonad
, Warning
, andThen
, andThen2
, combine
, combineDict
, combineMap
, errorToWarning
, fail
, fromApiSpec
, map
, map2
, map3
, recordType
, refToTypeName
, run
, stepOrFail
, succeed
, todo
, todoWithDefault
, typeToAnnotation
, typeToAnnotationMaybe
, withPath
, withWarning
)

import Common exposing (Field, Object, OneOfData, Type(..), TypeName, VariantName, toValueName)
import Dict
import Elm
import Elm.Annotation
import FastDict exposing (Dict)
Expand Down Expand Up @@ -404,3 +430,19 @@ refToTypeName ref =

_ ->
fail <| "Couldn't get the type ref (" ++ String.join "/" ref ++ ") for the response"


combineDict : Dict.Dict comparable (CliMonad a) -> CliMonad (Dict.Dict comparable a)
combineDict dict =
dict
|> Dict.foldr
(\k vcm rescm ->
map2
(\v res ->
( k, v ) :: res
)
vcm
rescm
)
(succeed [])
|> map Dict.fromList
Loading
Loading