Skip to content

Document complete schema for firebase.json #1409

Closed

Description

@samtstern

Originally suggested by @matheo here:
#1303 (comment)

We should document the complete schema of firebase.json in both human-readable and machine-readable formats. This file has expanded a lot and it's not always clear what's there and what the defaults are.

Activity

  1. self-assigned this
    on Jun 17, 2019
  2. long1eu commented on Dec 19, 2019

    @long1eu

    Any news on this?

  3. johnnyasantoss commented on Apr 21, 2020

    @johnnyasantoss

    Any updates?

    The provided link has a section called "The firebase.json file" that is not helpful. I still think that a json schema (like these ones) would be a better way to add documentation to this mysterious file.

  4. george43g commented on Jun 5, 2020

    @george43g

    so this repo: https://github.com/SirWindfield/vscode-firebase-configuration-schema-plugin

    Is a plugin for Vscode that supplies it with a schema for firebase.json

    I agree that a schema is needed, at least for autocomplete benefits. That repo is outdated and archived, I do not believe it's maintained. However, it contains a valid and working schema for firebase.json.

    PS: I'm tempted to fork the repo and update it... does anyone else want to help out?

  5. samtstern commented on Jun 5, 2020

    @samtstern
    ContributorAuthor

    @george43g if you do decide to contribute to that repo I would be happy to review your pull requests (I can't approve them, but I can at least give a Firebase stamp of approval).

    We actually have a few different needs around documenting the firebase.json schema:

    1. It would be great to have a TypeScript definition for use within this repository, right now it's all a lot of any when dealing with firebase.json
    2. We need some way to generate reference documentation for this file to host on firebase.google.com ... we use externs.js files in a lot of places now because our tooling supports it but I don't want to double down on that.
    3. We need to give developers like all of you autocomplete support in your editors. I assume JSON Schema is the most standardized way to do this? But maybe not ...
  6. jthegedus commented on Dec 29, 2020

    @jthegedus
    Contributor

    We need to give developers like all of you autocomplete support in your editors. I assume JSON Schema is the most standardized way to do this?

    @samtstern Yes, JSON Schema is the most standard way to support autocomplete in editors. IntelliJ uses this by default and VSCode can have support added by individual extensions as @george43g shows or by using popular plugins like the RedHat YAML plugin which pulls from JSON Schema store and provides both YAML and JSON autocomplete for all available schemas.

  7. jthegedus commented on Feb 9, 2021

    @jthegedus
    Contributor

    I'd like to add, having a utility function that validates a Firebase configuration would also be helpful (whether by the json schema or otherwise). I implemented a tool recently that reads a provided Firebase config and needed to implement a large Joi validation to check to ensure when Firebase Hosting rewrites to a Cloud Funtion that the functions config exists and is valid. It was painful and probably full of bugs.

    Additionally, it appears there are multple places in this repo where functions are validated but with different rules.

  8. samtstern commented on Jun 23, 2021

    @samtstern
    ContributorAuthor

    If anyone is still waiting on this, you can check out a JSON Schema for firebase.json here:
    https://github.com/firebase/firebase-tools/blob/master/schema/firebase-config.json

    This is just our first attempt to define the schema officially so it's possible that there are some configurations allowed in the real world that disagree with that file, please let me know if you find anything like that!

    Right now if we find JSON schema errors it's only exposed in firebase-debug.log but in a future CLI version we will make those more visible.

  9. jthegedus commented on Jun 24, 2021

    @jthegedus
    Contributor

    This is a great step @samtstern cheers!

    A use case that I am not sure JSON Schemas can cover is when a rewrite rule is defined to rewrite to a function, but the functions field is missing. I guess the default values for the functions object would be used 🤔 So I guess the request would be to the ability to parse a config that:

    1. validates a provided config against the JSON schema
    2. returned the computed config. That is, the config combined with the defaults.

    Currently even if I were to use this JSON Schema (and I will) to validate a config, I still have to hardcode the default values in my tool, like config.functions.source = "functions".

  10. samtstern commented on Jun 24, 2021

    @samtstern
    ContributorAuthor

    @jthegedus yeah the implicit defaults for products like Functions are definitely a bit of a problem here.

    Can you explain why you'd need to hardcode config.functions.source = "functions"? The config is valid without that.

  11. jthegedus commented on Jun 24, 2021

    @jthegedus
    Contributor

    Sorry, that example goes back to my prior comments above.

    I've built svelte-adapter-firebase which parses a users firebase.json file. If they define a rewrite rule to a function, I need to then parse their functions entrypoint, which requires knowing functions.source or fallback to the default value defined in firebase-tools. So my tool hardcodes the default location of ./functions/.

    firebase-tools CLI is run after my tool. As a plugin for SvelteKit it runs during app build, so I have to parse the config myself to ensure it has a valid configuration before this tool is even executed. It would be great if this tool provided a parser, similar to other IaC CLIs/APIs/Packages like https://github.com/architect/parser , that not only validated, but returned the computed final config with the defaults and all if omitted in the input config.


    Some missing items from the schema (I realise it is a first release):

    • site for Hosting
    • target for RTDB, Storage, Hosting
    • hosting.rewrites[].run.region can only be us-central1 (not sure if string literals can be enforced here)
    • hosting is valid as both an object and array
    • predeploy/postdeploy for most resources
    • predeploy/postdeploy are valid as both string and array of strings.
    • functions.runtime
  12. jthegedus commented on Jun 24, 2021

    @jthegedus
    Contributor

    An alternative to my above suggestiong would be to have all the default config values defined in a single JS object so consumers could object spread computedConfig = {...defaultConfig, ...providedConfig}. Last I checked the defaults are spread throughout the source code and difficult to find. As are the validation checks.

  13. samtstern commented on Jun 24, 2021

    @samtstern
    ContributorAuthor

    @jthegedus wow good eye! If you want to update the schema, you could send a PR here. The TypeScript is the source of truth:
    https://github.com/firebase/firebase-tools/blob/master/src/firebaseConfig.ts

    I agree we need to centralize the defaults. One of the issues is that they're a bit context dependent! For instance it's not true to say that the default for functions is { source: "functions" } because actually we only consider that default if you run a functions-specific command and we detect a functions/package.json file. So it's a bit of a mess!

  14. jthegedus commented on Jun 25, 2021

    @jthegedus
    Contributor

    For instance it's not true to say that the default for functions is { source: "functions" } because actually we only consider that default if you run a functions-specific command and we detect a functions/package.json file. So it's a bit of a mess!

    In the context of my usage I only look for functions if I first detect a Hosting Rewrite Rule that rewrites to a function, then I perform the lookup of functions.source or fallback.

    The context-dependent implementation does make this difficult.

  15. zanona commented on Apr 9, 2022

    @zanona

    It would be great if you could allow the $schema field on the JSON, so we could do this:

    firebase.json

    {
      "$schema": "./node_modules/firebase-tools/schema/firebase-config.json",
      "hosting": [...]
    }

    similar to what turborepo does, as it's great for validation.

  16. junaga commented on Jun 15, 2023

    @junaga

    why is my VS Code complaining?

    image

  17. o-az commented on Oct 28, 2023

    @o-az

    Pointing to the schema file from firebase-tools repo directly is the most convenient

    {
      "$schema": "https://raw.githubusercontent.com/firebase/firebase-tools/master/schema/firebase-config.json",
      "functions": {
        "source": "./"
      },
      // ...
    }
  18. Goldziher commented on Dec 4, 2023

    @Goldziher

    can you guys publish this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions